Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
414 views
in Technique[技术] by (71.8m points)

javascript - 这个服务人员没有缓存任何东西(this service worker isn't caching anything)

var myCachName = 'my-cache-v1';

self.addEventListener('install', function(event) {
    event.waitUntil(
        caches.open(myCachName)
        .then(cache =>
            cache.addAll[
                '/',
                '/img',
                '/js',
                '/css'
            ])
    )
});

self.addEventListener('fetch', function(event) {
    event.respondWith(
        caches.match(event.request)
        .then(function(response) {
            if (response) {
                return response;
            }
            return fetch(event.request);
        })
    );

});

self.addEventListener('activate', function(event) {
    event.waitUntil(
        caches.keys().then(cacheNames => {
            return Promise.all(
                cacheNames.map(cachName => {
                    if (cachName != myCachName) {
                        return caches.delete(cachName);
                    }
                })
            )
        })
    );
})

my problem is that I can see that the service worker is working, but when I check the cache there is nothing.

(我的问题是我可以看到服务工作者正在工作,但是当我检查缓存时却什么也没有。)

I couldn't figure what seems to be the issue.

(我不知道是什么问题。)

I tried to follow the step here https://developers.google.com/web/fundamentals/primers/service-workers

(我尝试按照此处的步骤进行操作https://developers.google.com/web/fundamentals/primers/service-workers)

  ask by mohammed alrajeh translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...