Force-refreshing only JavaScript files in Firefox and Chrome

64

8

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?

Graviton

Posted 2009-09-05T02:01:13.553

Reputation: 5 006

Answers

42

I do this myself for development. I use Ctrl+F5. It's like a force refresh. This refreshes the page including re-downloading any referenced JavaScript files or CSS files even if they were cached.

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

But please note that although I know this works in Firefox, and probably Internet Explorer, I am not sure if Ctrl+F5 works the same way in Chrome.

Also, iegik says:

On some browsers you can use `Ctrl+Shift+R to do the same task.

7wp

Posted 2009-09-05T02:01:13.553

Reputation: 1 410

1

For Chrome, F12 and rightclick the reload button. http://superuser.com/questions/220179/how-can-i-do-a-cache-refresh-in-google-chrome

– Cees Timmerman – 2015-03-24T08:52:01.747

control+F5 does the same thing as F5 for me on firefox. I can't get it to reload the javascript file that I've changed. – curtis – 2016-02-17T00:29:26.337

No good for OSX, I still have to restart Chrome – mdoar – 2010-08-26T23:04:31.993

CTRL-F5, or alternatively SHIFT-click on the reload button does the same thing. But these may fail to fully refresh assets (JS, CSS, images, etc.) loaded by frames/iframes contained within the main page; so if the script in question is inside an iframe, it might not reload as expected. To force it to, you can right-click -> "This Frame" -> hold down SHIFT and select "Reload". (You DO need the SHIFT, even though there's no indication in the menu that it does anything - as when clicking the reload button, SHIFT forces the reload to bypass the local cache and do a full reload from the server). – Doin – 2019-12-30T10:25:14.423

Oh, I was talking about Firefox above. Not sure if Chrome has exactly the same feature. – Doin – 2019-12-30T10:27:27.483

Great! I change the accepted answer to yours because yours is a simpler solution – Graviton – 2009-09-05T03:18:31.760

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 – 2009-09-05T03:27:18.840

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 – 2009-09-07T16:30:07.003

2Same with Chrome 21 beta on Win7 - refreshing the page with ctrl-f5 doesn't re-request the JS file (I'm using Charles to double verify). – Artem Russakovskii – 2012-07-13T03:24:20.020

1actually chrome treats first ctrl+f5 as normal refresh by design, subsequent ctrl+f5 (more then one) in short time will force reload of all sources – Zeela – 2012-09-07T12:06:58.070

Its not working at all times in chrome the disable cache is good. – Konga Raju – 2013-04-09T10:29:56.657

50

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.

avernet

Posted 2009-09-05T02:01:13.553

Reputation: 1 993

Thanks for the tip - I just checked and that option is in Chrome 14 also. – keybits – 2011-09-09T18:00:25.827

Genius! That's a great find. – Randomblue – 2011-09-30T21:00:15.517

Brilliant, I was looking for this. – Artem Russakovskii – 2012-07-13T03:25:10.270

... and just don't forget to uncheck the option after you are done with it. – Halil Özgür – 2012-11-30T11:43:40.663

On a second take, it looks like these options are only active when the devtools is visible: https://twitter.com/ChromiumDev/status/227356682890670080 (from http://stackoverflow.com/a/7000899/372654)

– Halil Özgür – 2012-11-30T11:55:50.350

saved lot of time on clearing cache manually – Konga Raju – 2013-04-09T10:30:29.973

8

I disagree with @7wp. Since some of your end users aren't familiar with the Ctrl+F5 function, and some aren't even aware of the differences between browsers and even the existance of other browsers (elders for example) you should force the browser to download a new copy of the JS/CSS files.

The best solution here is to add the timestamp at the end of the .js/.css filenames, or add the svn version which is a great idea too.

<script src="js/myfile.js?t=<?=time()?>" type="text/javascript"></script>

Alon Kogan

Posted 2009-09-05T02:01:13.553

Reputation: 181

5

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.

RoyalKnight

Posted 2009-09-05T02:01:13.553

Reputation: 361

Incognito is probably the way to go for Chrome. – mdoar – 2010-08-26T23:04:57.017

2

I open the JavaScript file in a separate tab, Shift + refresh, verify that I'm seeing the latest changes, then Shift + refresh the actual page (actually, in my case, frame in a frameset, which seems to make matters worse). This works almost all the time.

doug mayo-wells

Posted 2009-09-05T02:01:13.553

Reputation: 21

Works as a last resort! – Doin – 2019-12-30T10:17:30.453

1

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

Julio Bahar

Posted 2009-09-05T02:01:13.553

Reputation: 11

This does a hard refresh of the entire page, I don't think this just refreshes Javascript only. – Ivo Flipse – 2011-08-07T13:56:48.487

1

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

Try making the JavaScript code 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 Internet Explorer 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, Internet Explorer thinks it is a new file ;)

Greg

Posted 2009-09-05T02:01:13.553

Reputation:

1As 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 – 2011-01-21T13:50:51.447

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 – 2011-03-17T16:34:57.403

1Doesnt 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 – 2009-09-21T13:17:06.047

0

If you are working with JavaScript and worried about reloading the page to reflect JavaScript changes. Try to use the Chrome debugger, where you can make changes to your loaded JavaScript file(s) at run time and without using any reload can test new functions or changes you want to test.

Nikhil Joshi

Posted 2009-09-05T02:01:13.553

Reputation: 1

Welcome to Super User! Please read the question again carefully. Your answer does not answer the original question. – DavidPostill – 2016-12-20T13:42:33.030

0

In the latest Chrome it is available:

Enter image description here

Baljeetsingh

Posted 2009-09-05T02:01:13.553

Reputation: 227

Some elaboration wouldn't be amiss. – Peter Mortensen – 2018-12-08T20:34:11.190

0

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.

Jared Harley

Posted 2009-09-05T02:01:13.553

Reputation: 11 692

0

Add some dynamic date function at the end of your JavaScript file. It will force the browser to load the updated JavaScript file. Meaning, when including the .js file you could add .... xyz.js?

< ? php echo date('l jS \of F Y h:i:s A') ? >

Of course this could be removed once your debugging is done and ready to go live.

Chris

Posted 2009-09-05T02:01:13.553

Reputation: 9

This is not Javascript. – Natalie Adams – 2012-12-12T17:45:36.190

0

Go to content settings in Chrome, disable JavaScript and save.

Then, enable JavaScript again.

nisar

Posted 2009-09-05T02:01:13.553

Reputation: 1