Home » Questions » Computers [ Ask a new question ]

Force-refreshing only JavaScript files in Firefox and Chrome

Force-refreshing only JavaScript files in Firefox and Chrome

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.

Asked by: Guest | Views: 56
Total answers/comments: 5
Guest [Entry]

"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."
Guest [Entry]

"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>"
Guest [Entry]

"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 ;)"
Guest [Entry]

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

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.