2
我想缓存我的渐进网站应用程序中的静态以及远程文件。服务工作者:远程文件没有得到缓存
静态文件确实被缓存,但远程文件不是。
browser caching of static & remote files
下面的代码:提前
self.addEventListener('install', e => {
e.waitUntil(
caches.open('offline')
.then(cache => cache.addAll([
'/',
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css',
'https://code.jquery.com/jquery-3.2.1.js',
'scripts/firebase.js',
'scripts/localForage.js',
'old-index.html',
'scripts/main.js',
]))
);
});
感谢
下面是更新后的代码
var filesToCache = [
'.',
"https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.5.0/css/bootstrap-datepicker.css",
'https://code.jquery.com/jquery-3.2.1.js',
'scripts/firebase.js',
'scripts/localForage.js',
'cce.html',
'scripts/main.js',
'scripts/secondary.js',
'https://cdn.datatables.net/1.10.15/css/jquery.dataTables.min.css'
];
var staticCacheName = 'pages-cache-v1';
self.addEventListener('install', function(event) {
console.log('Attempting to install service worker and cache static assets');
event.waitUntil(
caches.open(staticCacheName)
.then(function(cache) {
return cache.addAll(filesToCache);
})
);
});
我试过的示例代码,以及在一个文档中,但问题仍然涉及。 – user3287355
是否有任何其他问题,哪些代码不起作用? – user3287355