我创建了一个服务工作者,它遍历每个文件以将它们添加到缓存存储中,但每次都不会保存所有文件。此外,每次我尝试使用相同的代码在不同的设备上创建应用程序时,即使循环是静态的,它也会选择要保存的文件。
有没有人知道这可能是问题?
var cacheName = 'erh-cache-v1';
var filesToCache = [
'/',
'index.html',
'/dragon.js',
'/app.js',
'/menu.html',
'/activeShooter.html',
'/buildings.json',
'/demonstrations.html',
'/dragon.js',
'/earthquakes.html',
'/elevatorMalfunction.html',
'/employees.json',
'/fireEvacuation.html',
'/flooding.html',
'/bombThreat.html',
'/gas.html',
'/jquery-3.1.0.js',
'/jquery.cookie.js',
'/jquery.popmenu.min.js',
'/keywords.json',
'/localEmergencyContacts.html',
'/manifest.json',
'/medicalAssistance.html',
'/menu.html',
'/sw.js',
'/powerFailure.html',
'/script.js',
'/search.png',
'/settings.html',
'/severeWeather.html',
'/site.js',
'/styles.css',
'/suspiciousIndividuals.html',
'/suspiciouspackage.html',
'/theft.html',
'/threateningBehaviour.html',
'/unknownOrSuspiciousSubstances.html',
'/violenceAndHarassment.html'
];
self.addEventListener('install', function(e) {
console.log('[ServiceWorker] Install');
e.waitUntil(
caches.open(cacheName).then(function(cache) {
console.log('[ServiceWorker] Caching app shell');
return cache.addAll(filesToCache);
})
);
});