Chrome install Service Worker addAll failed to fetch

后端 未结 1 1397
别那么骄傲
别那么骄傲 2021-01-21 01:17

I am using a service worker to provide caching for my site\'s assets (HTML, JS, CSS).

When I use Firefox my sw.js is installed correctly and the required files cached. I

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-21 01:55

    cache.addAll(CACHE_FILES)
    

    will fail when 1 of the file is not accessible (HTTP 400,401 etc, also 5XX and 3XX sometimes) to avoid failing all when 1 fail use individual catch statement in a map loop like here https://github.com/GrosSacASac/server-in-the-browser/blob/master/client/js/service_worker.js#L168

    the fact that it does not fail with empty array probably means you have an inaccessible resource in CACHE_FILES.

    Maybe firefox is less restrective and caches the body of the 400 response.

    Inside your fetch handler you try to use caches.match directly but I think that is not legal. you must open the caches first and then from an opened cache you can do cache.match. See https://github.com/GrosSacASac/server-in-the-browser/blob/master/client/js/service_worker.js#L143

    0 讨论(0)
提交回复
热议问题