How to cache entire website first login using cache API (Service Worker)

牧云@^-^@ 提交于 2020-04-18 05:46:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!