问题
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?
回答1:
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.
回答2:
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>
回答3:
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() * 1000000));
Remember to remove the query string before the code goes into production!
来源:https://stackoverflow.com/questions/3775518/force-reload-prevent-cache-of-web-workers