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

有帮助吗?

解决方案

RequireJS has a cache busting property that you can use -:

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

Edit -: However, as Ian pointed out below, in their documents it is recommended not to use it this way for production code.

Everytime you push a new commit to production maybe you can instead add a specific version number.

require.config({
        urlArgs: "ver=1.1.1"
    });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top