[ACCEPTED]-Forcing cache expiration from a JavaScript file-caching

Accepted answer
Score: 19

In short... no.

You can add something to 4 the end of the source address of the script 3 tag. Browsers will treat this as a different 2 file to the one they have currently cached.

<script src="/js/something.js?version=2"></script>

Not 1 sure about your other options.

Score: 7

In HTML5 you can use Application Cache, that 14 way you can control when the cache should 13 expire

You need to add the path to the manifest

<!DOCTYPE HTML><html manifest="demo.appcache">

In 12 your demo.appcache file you can just place 11 each file that you want to cache

# 2013-01-01 v1.0.0

When you 10 want the browser to download a new file 9 you can update the manifest

# 2013-02-01 v1.0.1

Just be sure 8 to modify the cache manifest with the publish 7 date or the version (or something else) that 6 way when the browser sees that the manifest 5 has change it will download all files in 4 it.

If the manifest is not change, the browser 3 will not update the local file, even if 2 that file was modify on the server.

For further 1 information please take a look at HTML5 Application Cache

Score: 1

You could add a dummy parameter to your 9 URLs

<script src='oldscriptname.js?foo=bar'></script>

[e: f; b]

The main problem is that if 8 you set up the expiration with a simple 7 "Expires" header, then the browsers that 6 have the file cached won't even bother to 5 contact you for it. Even if there were a 4 way for the script to whack the browser 3 in the head and clear the cache, your old 2 script doesn't do that, so you have no way to get that 1 functionality out to the clients.

Score: 0

You can force to reload an cacheated document 3 with on javascript:


The true command indicate 2 the browser must to reload the page without 1 cache.

More Related questions