问题
I have a website with a few pages. I know all URL of the website and asserts and its a PHP based.
My main objective is in the first login, I want to cache the entire website.
Currently, I used SW to caching by navigation, that works fine.
What is the better approach?
Following is the code I tried.
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(CACHE_DYNAMIC_NAME)
.then(function (cache) {
cache.addAll([
'/assets/app/css/vendor.css',
'/assets/app/css/app.css',
'offline.html',
'******** I added other all known links here',
'/assets/app/js/pwa.js',
'/assets/app/js/vendor.js',
'/assets/app/js/app.js',
]).then(
function() {
DEBUG && console.log('[Service Worker] Static caching done.');
},
);
DEBUG && console.log('[Service Worker] Pre caching staticsApp Shell.');
})
)
});
来源:https://stackoverflow.com/questions/61227133/how-to-cache-entire-website-first-login-using-cache-api-service-worker