JavaScript file not updating no matter what I do

I have an external JavaScript file and whether in FireFox or Chrome, whether all browsing data is cleared, it will NOT update no matter what. I believe something happened when I made a backup of my file, which I simply added “_thedate” to the end of the name. Then Save As back to the original name.

Now I cannot seem to get rid of the old JS no matter what unless I change the name of the file, which I really don’t want to do, or add the script to the PHP page, which crowds it.

Anyone know the solution to this?


You are sure you are linking to the same file and then editing that same file?

On some browser, you can use CTRL F5 to force a refresh (on the PC). On the Mac, it is Cmd Shift R

Firebug also has a net tab with “Disable Browser Cache”.

But I want to give a warning here: even if you can hard refresh, how do you know your customers are getting the latest version? So you need to check, rather than just making sure you and your program manager can do a hard refresh and just go home and take the paycheck next month. If you want to do a job that change the world for the better, or leave the world a little bit better than you found it, you need to investigate more to make sure it works for your customers too (or else, sometimes the customer may call tech support, and tech support may read the script of “clear out the cookies and it will work”, which is what happens to me sometimes). Some methods down at the bottom of this post can ensure the customers get the latest version.

Update 2020:

If you are using Chrome and the DevTools is open, you can click and hold the Refresh icon in front of the address bar, and a box will pop up, and you can choose to “Hard Reload” or even “Empty Cache and Hard Reload”:

hard reload button

Update 2017:

If you use the Google Chrome debugger, it is the same, you can go to the Network section and make sure the “Disable cache (while DevTools is open)” is checked, in the Settings of the debugger panel.

Also, when you link the JavaScript file, use

<script src="my-js-file.js?v=1"></script>

or v=2, and so forth, when you definitely want to refresh the file. Or you can go to the console and do a and get a timestamp, such as 1491313943549, and use

<script src="my-js-file.js?t=1491313943549"></script>

Some building tools will do that automatically for you, or can be configured to do that, making it something like:

<script src="main.742a4952.js"></script>

which essentially will bust the cache.

Note that when you use the v=2 or t=1491313943549, or main.742a4952.js, you also have the advantage that for your users, they definitely will get the newer version as well.

Source: stackoverflow