[PWA] 11. Serve skeleton cache for root

Posted Answer1215

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[PWA] 11. Serve skeleton cache for root相关的知识,希望对你有一定的参考价值。

Intead of cache the root floder, we want to cache skeleton instead.

self.addEventListener(‘install‘, function (event) {
    event.waitUntil(
        caches.open(staticCacheName).then(function (cache) {
            return cache.addAll([
                ‘/skeleton,
                ‘js/main.js‘,
                ‘css/main.css‘,
                ‘imgs/icon.png‘,
                ‘https://fonts.gstatic.com/s/roboto/v15/2UX7WLTfW3W8TclTUvlFyQ.woff‘,
                ‘https://fonts.gstatic.com/s/roboto/v15/d-6IYplOFocCacKzxwXSOD8E0i7KZn-EPnyo3HZu7kw.woff‘
            ]);
        })
    );
});

 

Respond to requests for the root page with thepage skeleton from the cache:

self.addEventListener(‘fetch‘, function (event) {
    // use the page skeleton from the cache
    let requestUrl = new URL(event.request.url);
    if(requestUrl.origin === location.origin){
        if(requestUrl.pathname === ‘/‘){
            event.respondWith(
                caches.match(‘/skeleton‘)
            );
            return; 
        }
    }


    event.respondWith(
        caches.match(event.request).then(function (response) {
            return response || fetch(event.request);
        })
    );
});

 

以上是关于[PWA] 11. Serve skeleton cache for root的主要内容,如果未能解决你的问题,请参考以下文章

dpdk20.11.1学习-2.skeleton

dpdk20.11.1学习-2.skeleton

dpdk20.11.1学习-2.skeleton

dpdk20.11.1学习-2.skeleton

iOS 11.3 中不使用 PWA 图标

iOS 11.3 中 PWA 无推送通知限制的解决方法?