Chrome not loading latest version of web worker sc

2019-04-22 02:15发布

If I edit my web worker script and refresh the page, the web worker script is a cached version. I am reasonably confident it is not my webserver, because I can immediately load the latest copies of all other files, and even restarting the webserver does not fix the problem. It only loads the newest version of the web worker script if I reboot chrome, which is highly inefficient, needless to say! It doesn't fix it even if I restart chrome. Is there anything I can do to get around this?

6条回答
一纸荒年 Trace。
2楼-- · 2019-04-22 02:28

Your web server determines how cachable a given web resource is and the browser attempts to respect those settings, caching resources that the web server says it is OK to cache, not caching things it says shouldn't be cached.

If you want to change that, you have these options:

  1. Clear the browser cache manually
  2. Temporarily turn off browser caching.
  3. Temporarily change the settings on your web server to instruct the browser not to cache
  4. Override the cache for just this one web page (shift-F5 in some browsers) to force a reload of new content
  5. Add a query parameter to the URL of the web worker script that you change each time you want it to load a new version.
查看更多
疯言疯语
3楼-- · 2019-04-22 02:32

You must close all tabs which opening this page. Open only one 1 then Ctrl + Shift + R to refresh then the cache will be clear.

查看更多
Bombasti
4楼-- · 2019-04-22 02:35

In your install event, before the call to event.waitUntil add:

if (self.skipWaiting) { self.skipWaiting(); }

Source

Also, you can follow this development workflow:

  1. Configure your server to serve your Service Worker script as non-cacheable (cache-control: no-cache)
  2. After you made changes to your service worker script:
    1. close all but one of the tabs pointing to your web application
    2. hit shift-reload to bypass the service worker as to ensure that the remaining tab isn't under the control of a service worker
    3. hit reload to let the newer version of the Service Worker control the page.

Source

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-04-22 02:44

Add <script src="your_worker_path"></scripts> to your page head to force cache update.
Include code of your worker in if(typeof window == "undefined"){...} to avoid it starting on page reload

查看更多
萌系小妹纸
6楼-- · 2019-04-22 02:45

On my Linux Chrome I have to right click (or long click) the reload button and select "Empty Cache and Hard Reload" to get the latest version

查看更多
甜甜的少女心
7楼-- · 2019-04-22 02:47

Did you try a hard refresh? Ctrl-r?

查看更多
登录 后发表回答