I want to clear only JavaScript files from my web browsers (Firefox and Chrome). I am doing JavaScript debugging, and it's annoying that my JS just won't get updated whenever I change my JS files. The only thing I can do now is to clear my cookies, but doing that erases all of my browsing history.

How can I clear/refresh the JavaScript files that have been loaded into my browsers without clearing out other files?

link|improve this question

53% accept rate
feedback

7 Answers

up vote 16 down vote accepted

I do this myself for development. I use CTRL-F5. Its like a force refresh. This refreshes the page including re-downloading any referenced JS files or CSS files even if they were cached.

It will NOT clear anything else such as your browsing history.

link|improve this answer
Great! I change the accepted answer to yours because yours is a simpler solution – Graviton Sep 5 '09 at 3:18
I appreciate that... But please note that although I know this works in Firefox, and probably IE, I am not sure if CTRL-F5 works the same way in Chrome. – 7wp Sep 5 '09 at 3:27
Well, it doesn't really matter because even though I use Chrome as my main browser, but I use firefox as my debugging browser, thanks to firebug – Graviton Sep 7 '09 at 16:30
No good for OSX, I still have to restart Chrome – mdoar Aug 26 '10 at 23:04
feedback

With Chrome:

Starting with Chrome 15, open the Developer Tools, click on the cogwheel at bottom left of the screen, and select the checkbox Disable cache.

Disable cache in Chrome 15 and up

This way, you will be sure that resources are always reloaded from the server, and you don't have to manually clear the cache, which might also remove cached data for unrelated sites.

link|improve this answer
Thanks for the tip - I just checked and that option is in Chrome 14 also. – knitatoms Sep 9 '11 at 18:00
Genius! That's a great find. – Justin Sep 30 '11 at 21:00
feedback

You might want to try clearing just your cache, and not your entire browsing, history, cookies, passwords, saved form data, and whatnot (the default).

In Firefox 3.5, go to

Tools » Clear Recent History...

Then make sure only "Cache" is selected before selecting "Clear Now."

In Chrome (don't know what particular version you're using, as I use the dev builds), go to

Wrench Icon (Tools) » Options » Personal Stuff tab » Clear browsing data...

Again, make sure only "Empty the cache" is checked.

Alternatively, you can try opening up a new Private session in Firefox or Incognito window in Chrome; neither should cache any files (including your .JS files) you automatically download and process when browsing.

link|improve this answer
Incognito is probably the way to go for Chrome. – mdoar Aug 26 '10 at 23:04
feedback

I've been using a little trick one a site that I'm working on...for the same reasons as you. I make small changes and have js loaded by js and want to make sure that I'm always working with the current (non-cached) script.

try making the JS you are loading into a php file...simply put <?php ?> at the beginning and put on the ext of .php.

var fileref=document.createElement('script');

fileref.setAttribute("type","text/javascript");

//the Date added to the file doesn't effect the results but helps IE be sure to refresh the data and not use cache

var d = new Date();

var t = d.getTime();

 fileref.setAttribute("src", filename+".php?date="+t);

 fileref.setAttribute("id", filename);

Because the name changes, IE thinks it a new file ;)

link|improve this answer
Doesnt need to change the name to '.php'. If you put 'filename.js?t='+t the result is the same. You can do it with '.css' too. All ours production systems use this trick to certify that the clients uses the right content files. – Leonel Martins Sep 21 '09 at 13:17
As a note, we tend to use the SVN revision number instead of date/time. That way we get caching benefits, and refresh only when we actually commit. – Groo Jan 21 '11 at 13:50
Thanks so much! This trick totally slipped my mind. I've been battling this issue for days and this'll do it for me. I just put this at the end of the url: "?<?php echo time() ?>" – thrashr888 Mar 17 '11 at 16:34
feedback

In chrome you can just press Ctrl and click the refresh button. I discovered this by chance.

link|improve this answer
This does a hard refresh of the entire page, I don't think this just refreshes Javascript only. – Ivo Flipse Aug 7 '11 at 13:56
feedback

I've not used it myself, but the Firefox Add-on "Clear Cache Button" might be of use. I read through their documentation, so I'm not sure if it clears your browsing history too.

link|improve this answer
feedback

It isn't possible in Chrome. Ctrl-F5 does not reload JavaScript. The Chrome issue for it is at http://code.google.com/p/chromium/issues/detail?id=8742.

link|improve this answer
The issue has been marked as fixed, but it is not for a ctrl-shift-F5 to ignore the cache, as it does in Firefox. The issue is about adding a keyboard shortcut to quickly clear the cache. So I am afraid that this is still impossible to do with Chrome, as mentioned in this answer. – Alessandro Vernet Sep 2 '11 at 17:59
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.