强制重新加载/阻止 Web Workers 缓存
我注意到大多数浏览器(尤其是 Chrome)似乎会缓存 Web Worker 脚本,即使您强制页面重新加载(SHIFT+F5 等)也是如此。我发现强制更新缓存的唯一可靠方法是将工作脚本的路径输入地址栏中并单独强制重新加载它。
显然,在尝试开发任何东西时,这是一种巨大的痛苦。有谁知道一种可靠的方法来阻止浏览器缓存工作脚本或强制它以简单的方式重新加载它们?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个老问题,也是我今天使用的一个老解决方案。开发时,创建 Web Worker,并将随机数查询字符串添加到 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:
Remember to remove the query string before the code goes into production!
如果您无权访问服务器配置文件,或者您的元标记没有被遵守,一个快速的解决方法是包含“Web Worker 脚本”来加载 html 头。
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.
您是否尝试过使用
Cache-Control: no-cache
HTTP 标头来避免工作脚本被缓存?通常,您可以通过设置适当的 HTTP 标头来获得所需的缓存行为。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.