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 k开发者_运维百科now of a reliable way to either stop the browser from caching worker scripts OR force it to reload them in a simple manner?
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>
Have you tried using the Cache-Control: no-cache
HTTP header to avoid having the worker script cached at all? You can generally get the caching behavior that you want by setting the appropriate HTTP headers.
精彩评论