Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force reload/prevent cache of Web Workers

I've noticed that most browsers (Chrome in particular) seem to cache web worker scripts even after you force the page to reload (SHIFT+F5, etc). The only reliable way I've found to force the cache to update is to type the worker script's path into the address bar and force reload it separately.

Obviously this is a royal pain when trying to develop, well, anything. Does anyone know of a reliable way to either stop the browser from caching worker scripts OR force it to reload them in a simple manner?

like image 446
Toji Avatar asked Sep 23 '10 04:09

Toji


People also ask

How do I force a browser to ignore cache?

Chrome, Firefox, or Edge for Windows: Press Ctrl+F5 (If that doesn't work, try Shift+F5 or Ctrl+Shift+R). Chrome or Firefox for Mac: Press Shift+Command+R. Safari for Mac: There is no simple keyboard shortcut to force a hard refresh.

What method cancels web worker?

terminate() The terminate() method of the Worker interface immediately terminates the Worker .


2 Answers

An old question, and an old solution that I've used today. When developing, create the web worker with a random number query string added to the worker file:

var worker = new Worker('path/to/worker/file.js' + '?' + Math.random());

Remember to remove the query string before the code goes into production!

like image 142
KaliedaRik Avatar answered Oct 28 '22 07:10

KaliedaRik


If you do not have access to the server configuration files, or your meta tags are not being honored, a quick workaround would be to include the "web worker script" to load with the html head.

   <html>
     <head>
        <meta http-equiv="Cache-control" content="no-cache">
        <script src="jquery_or_other_lib.js"></script>
        <script src="normal_site_scripts.js"></script>
        <script src="webworker.js"></script>
     </head>
     <body>
     </body
   </html>
like image 43
Scryptronic Avatar answered Oct 28 '22 06:10

Scryptronic