2

A client would report a bug in our JS-heavy app, we fixed it, but the client's browser still using the cached copy. This happens a lot, and asking our clients to flush their browser cache seems very low-tech and troublesome.

We are aware of the ?ver=xxx workaround, but we use RequireJS so it's not easy to apply such hack.

Would HTTP cache control work? However, we noticed IIS does not pick up the JS file changes right away and the HTTP header (last modified) does not reflect the latest changes.

Would ETag work better? Is it better or worse then last modified on IIS?

Any other solutions? Thanks

4

1 回答 1

5

RequireJS 有一个缓存破坏属性,你可以使用它——:

require.config({
    urlArgs: "bust=" + (new Date()).getTime()
});

编辑-:但是,正如 Ian 在下面指出的那样,在他们的文档中,建议不要以这种方式将其用于生产代码。

每次您将新的提交推送到生产环境时,也许您可​​以添加一个特定的版本号。

require.config({
        urlArgs: "ver=1.1.1"
    });
于 2013-08-09T18:36:44.347 回答