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?
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.
terminate() The terminate() method of the Worker interface immediately terminates the Worker .
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!
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With