Aggressive JavaScript caching

前端 未结 9 959
北荒
北荒 2020-12-24 08:45

I\'ve run into a problem where I make changes to a few JavaScript files that are referenced in an HTML file, but the browser doesn\'t see the changes. It holds onto the copy

相关标签:
9条回答
  • 2020-12-24 09:23

    I am also of the method of just renaming things. It never fails, and is fairly easy to do.

    0 讨论(0)
  • 2020-12-24 09:29

    For what it is worth, I saw deviantART site, quite a big one, serving their JS files as 54504.js. I just checked and see they now serve them as v6core.css?-5855446573 v6core_jc.js?4150339741 etc.

    If the problem of query string comes from the server, I suppose you can control that more or less.

    0 讨论(0)
  • 2020-12-24 09:33

    With every release, we simply prepend a monotonically increasing integer to the root path of all our static assets, which forces the client to reload (we've seen the query string method break in IE6 before). For example:

    • Release 1: http://www.foo.com/1/js/foo.js
    • Release 2: http://www.foo.com/2/js/foo.js

    It requires rejiggering links with each release, but we've built functionality to automatically change the links into our deployment tools.

    Once you do this, you can use Expires/Cache-Control headers that let the client cache JS resources "forever", since the path changes with each release, which i think is what @JasonCohen was getting at.

    0 讨论(0)
提交回复
热议问题