Service-worker force update of new assets

后端 未结 3 1852
灰色年华
灰色年华 2020-12-05 00:13

I\'ve been reading through the html5rocks Introduction to service worker article and have created a basic service worker that caches the page, JS and CSS which works as expe

3条回答
  •  一向
    一向 (楼主)
    2020-12-05 00:22

    One way of invalidating the cache would be to bump version of the CACHE_NAME whenever you change anything in the cached files. Since that change would change the service-worker.js browser would load a newer version and you'd have a chance to delete the old caches and create new ones. And you can delete the old cache in the activate handler. This is the strategy described in prefetch sample. If you already using some kind of version stamps on CSS files make sure that they find their way into service worker script.

    That of course does not change the fact that cache headers on CSS file need to be set correctly. Otherwise service worker will just load the file that is already cached in browser cache.

提交回复
热议问题