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?
7 Answers
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
-
To long click, hold down the mouse button until the menu opens up. @Brian: I didn't even know that was there. Ctrl+F5 wasn't working for some reason, but this worked perfectly. May 31, 2013 at 23:05
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:
- Clear the browser cache manually
- Temporarily turn off browser caching.
- Temporarily change the settings on your web server to instruct the browser not to cache
- Override the cache for just this one web page (shift-F5 in some browsers) to force a reload of new content
- 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.
-
4Chrome's hard refresh does not refresh workers and still uses the cached version.– rivJun 30, 2015 at 11:10
-
If you still find that with this answer your serviceworker is not updated, check if it contains errors. Since if the serviceworker contains javascript errors and fails to install, the old version will still remain in use. Sep 12, 2016 at 7:50
-
@BasGoossen - In case you didn't realize, this question is about web workers (scripts that run in a different thread in a web page), not service workers (different things). Sep 12, 2016 at 12:16
-
@jfriend00 oops, my bad. Might still apply to webworkers as well though? Was working a lot with serviceworkers lately, so that coused the confusion. Sep 13, 2016 at 21:29
-
@BasGoossen - There's no webWorker functionality that might auto-load an old script after an error in a newer script. Sep 13, 2016 at 21:36
Did you try a hard refresh? Ctrl-r?
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
In your install
event, before the call to event.waitUntil
add:
if (self.skipWaiting) { self.skipWaiting(); }
Also, you can follow this development workflow:
- Configure your server to serve your Service Worker script as non-cacheable (cache-control: no-cache)
- After you made changes to your service worker script:
- close all but one of the tabs pointing to your web application
- hit shift-reload to bypass the service worker as to ensure that the remaining tab isn't under the control of a service worker
- hit reload to let the newer version of the Service Worker control the page.
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.
What I found works is:
- open a new tab, with the URL to the SharedWorker script,
- you should see that this tab contains the cached version of the script
- if you then Shift-Reload that tab, the browser is forced to update the cached file
Chrome's reloading of "resources" on "shift-reload" seems to be... variable.
I hope you found this: chrome://inspect/#workers. You can terminate the worker here