为什么客户端不会在公用文件夹中收到此脚本的新版本? [英] Why won't the client receive new versions of this script in the public folder?

查看:74
本文介绍了为什么客户端不会在公用文件夹中收到此脚本的新版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目中有一个公共文件夹和一个脚本: public / worker.js ,其中包含一段代码:

In my project there is a public folder and a script inside it: public/worker.js, which contains a piece of code:

alert('foo');

我使用工人调用此脚本:

I call this script using a Worker:

new Worker('worker.js');

我启动Meteor并连接到我的应用程序。 foo 已收到提醒。

如果我将 public / worker.js 代码更改为其他任何内容:

I launch Meteor and connect to my app. foo is alerted.
If I change the public/worker.js code to anything else:

alert('bar');

服务器刷新客户端,客户端刷新页面但不会获取新代码,而是使用旧的(警告 foo 而不是新的闪亮)。清除缓存然后刷新修复问题。 CTRL + F5 无法修复此缓存问题,它似乎不适用于此类脚本调用(至少不适用于我测试过的Firefox版本)。

The server refreshes the clients, the client refreshes the page but won't get the new code, instead using the old one (alerting foo instead of the new shiny bar). Clearing the cache then refreshing fixes the issue. CTRL+F5 does not fix this cache issue, it does not seem to work for this kind of script call (at least not on the version of Firefox I tested it with).

为什么会发生这种情况呢?

如何防止它?

Why is this happening, exactly?
How can I prevent it?

推荐答案

脚本被缓存,浏览器不会从服务器中提取新版本。

The script is cached and the browser does not pull the new version from the server.

我们需要编辑使用以下代码服务器端请求 / workers 文件夹中的文件(我将它包装在一个包含 api.use('webapp)的包中')):

We need to edit the header of the requests for the files in the /workers folder, using the following code server-side (I wrapped it in a package with api.use('webapp')):

WebApp.rawConnectHandlers.use('/workers', function(req, res, next) {
  res.setHeader('cache-control', 'must-revalidate');
  next();
});

使用 WebApp.connectHandlers 不起作用,从来没有调用回调,所以我使用 rawConnectHandlers

Using WebApp.connectHandlers did not work, the callback was never called, so I used rawConnectHandlers instead.

我不是100%肯定它是最好的方式去,但它的工作原理。

I am not 100% sure it is the best way to go, but it works.

这篇关于为什么客户端不会在公用文件夹中收到此脚本的新版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆