I'm using IE 8 on Vista, and everytime I change a javascript file and then start debugging, I have to hit Ctrl+F5 to have it reload my javascript. Is there any way to make it automatically reload javascript when I start debugging, but not lose the performance gains when just browsing the net?
Yeah yeah I know you probably don't like IE, but keep in mind the question isn't "What's the best browser?".
In javascript I think that it is not possible, because modern browsers have a policy on security in javascripts.. and clearing the cache is a very violating one.
You can try to add
In your header, but you will have performance loss.
Add a date of modification of js file at the end of your URL. With PHP it would look something like this:
When your script will be reloaded every time you update it.
If you are running ASP.Net, check out the Bundling and Minification module available in ASP.Net 4.5.
http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification
You can declare a "bundle" that points to your javascript file. Every time your file changes, it will generate a new querystring suffix... but will only do so when the file changes. This makes it super simple to deploy updates, because you don't even have to think about updating your tags with new version numbers.
It can also bundle multiple .js files together into one file, and minify them, all in one step. Ditto for css.
To eliminate the need to repeatedly press F5 in an IE tab while developing a website, use ReloadIt.
For each webpage displayed in IE, you can configure a filename, a directory, or a set of them. If any change occurs in any of those configured paths, ReloadIt refreshes the IE tab. A simple tool. It just works.
This will reload everything, not just javascript.
Add a string at the end of your URL to break the cache. I usually do (with PHP):
So that it reloads every time while I'm working on it, and then take it off when it goes into production. In reality I abstract this out a little more but the idea remains the same.
If you check out the source of this website, they append the revision number at the end of the URL in a similar fashion to force the changes upon us whenever they update the javascript files.
This should do the trick for ASP.NET. The concept is the same as shown in the PHP example. Since the URL is different everytime the script is loaded, neither browser of proxy should cache the file. I'm used to put my JavaScript code into separate files, and wasted a significant amount of time with Visual Studio until I realized that it wouldn't reload the JavaScript files.
Full example:
Obvously, this solution should only be used during the development stage, and should be removed before posting the site.