Search code examples
htmlcsscachingmetadatabrowser-cache

Tell Browsers to update the cache if cache date is over a certain date


Is there a meta tag or something I can use that tells the browser to not use a cache from before a certain date.

e.g.

<meta "only use cache if cache is AFTER 4/4/2013">

If the cache is old it needs to download all the new Javascript, CSS, Images, etc..

I make a lot of updates to the site and then it screws up anyone who still has a cache (and you can't expect them to know to press ctrl+f5 or ctrl+r).


Solution

  • I usually just add a get parameter on the end with the version of the script I am presenting them

    so if you have your javascript at

    www.example.com/script.js
    

    use the url

    www.example.com/script.js?foo=1
    

    when I increment the value of foo everytime, this forces the browser to refetch the script.