我注意到一件事,所有js和CSS都加载了多次。 请在下面找到服务人员代码和显示多个加载情况的示例jQuery js图片
var version = "1.0.0";
var CACHE_NAME = "test-" + version;
var filesToCache = [
// some css and js files
];
self.addEventListener('install', function (e) {
e.waitUntil(caches.open(CACHE_NAME).then(function (cache) {
return cache.addAll(filesToCache);;
}).then(function (e) {
return self.skipWaiting();
}));
});
self.addEventListener('fetch', function (event) {
event.respondWith(caches.match(event.request).then(function (response) {
// check if the cache has the response
if (response) {
return response;
} else {
return response || fetch(event.request);
}
}).catch(function (e) {
console.log("service worker error:-"+e);
}));
});