SW缓存图像文件,但不缓存JS(大小为0字节)
/*serviceWorker*/ if ('serviceWorker' in navigator) { navigator.serviceWorker .register('service-worker.js', { scope: '/' }) .then(function(registration) { console.log("Service Worker Registered"); }) .catch(function(err) { console.log("Service Worker Failed to Register", err); }) }; const CACHE = 'cache-only-v1'; const timeout = 400; self.addEventListener('install', (event) => { event.waitUntil( caches.open(CACHE).then((cache) => { return cache.addAll([ '/sys/Raycaster/3d.js', '/sys/js/popmotion.global.min.js', '/sys/js/anime.min.js', 'sys/b/bgFeedback.jpg', '/sys/b/ic.svg', '/sys/b/ani/img_ani_1.webp', '/sys/b/ani/img_ani_2.webp', '/sys/b/ani/img_ani_3.webp', '/sys/printProd/p.webp', '/sys/printProd/p2.webp', '/sys/printProd/p3.webp', '/sys/printProd/p4.webp', '/sys/printProd/p5.webp', '/sys/printProd/p6.webp', '/sys/printProd/p7.webp', '/sys/printProd/p8.webp', '/sys/printProd/p9.webp', '/sys/printProd/p10.webp', '/sys/printProd/p11.webp', '/sys/printProd/p12.webp', '/sys/sliderInSlider/01_el.webp', '/sys/sliderInSlider/02_dv.webp', '/sys/sliderInSlider/05_snth.webp', '/sys/sliderInSlider/06_ton.webp', '/sys/sliderInSlider/07_pty.webp', '/sys/sliderInSlider/08_lyu.webp', '/sys/sliderInSlider/09_kar.webp' ]); }) ); });
答案 0 :(得分:0)
chrome DevTools中显示的信息基于unset PYTHONPATH
source ~/.bashrc
,有时它不能反映现实。您的js文件已缓存,但是Response Headers
中没有Content-Lenght
。
要测试它,您可以执行以下操作:
Headers
此代码将在缓存中检入popmotion.global.min.js,并显示其内容。