强制重新加载/阻止 Web Workers 缓存

发布于 2024-09-24 17:50:50 字数 192 浏览 7 评论 0原文

我注意到大多数浏览器(尤其是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

卷耳 2024-10-01 17:50:50

一个老问题,也是我今天使用的一个老解决方案。开发时,创建 Web Worker,并将随机数查询字符串添加到 Worker 文件中:

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

请记住在代码投入生产之前删除查询字符串!

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!

爱,才寂寞 2024-10-01 17:50:50

如果您无权访问服务器配置文件,或者您的元标记没有被遵守,一个快速的解决方法是包含“Web Worker 脚本”来加载 html 头。

   <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 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>
望喜 2024-10-01 17:50:50

您是否尝试过使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文