45

How can I disable cache in IE8 ? We are doing Javascript development and testing it in IE8, but we have to clear the cache every time we make changes to the Javascript files.

Lydon Ch
  • 8,637
  • 20
  • 79
  • 132
  • 1
    If you have issues with it, so might your users. Better to use one of the non-accepted answers to force a refresh from the server. – user420667 Oct 16 '13 at 20:30

10 Answers10

70

Go to Internet Options. On the General tab, under Browsing History click Settings. Select the "Every time I visit the webpage" radio button.

This doesn't "disable" the cache per se, but it should fix your underlying problem - the JS files should be reloaded every time.

EMP
  • 59,148
  • 53
  • 164
  • 220
  • That's not something I can guarantee, you'll just have to test it. – EMP May 03 '10 at 03:58
  • 6
    In my experience this does not work for nested pages or controls that contain javascript. – Dan Bailiff Mar 09 '11 at 21:38
  • 6
    A more reliable way is to do it from dev tools menu. `Cache -> Always Refresh From Server` as suggested buy [Mac](http://stackoverflow.com/a/15576678/227299) – Ruan Mendes May 16 '13 at 18:26
16

Ctrl+F5 Should cause a full page refresh including all that cached javascript.

Occasionally though, you'll still need a cache clear, because even Ctrl+F5 won't work, for reasons beyond comprehension IE can't even get "refresh" right 100% of the time.

Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
11

If that fails, a random parameter on the query string will do it:

index.html?a=346456

user97410
  • 714
  • 1
  • 6
  • 22
10

Load you JavaScript this way.

<html>
...
<script type="text/javascript">
document.write('<script src="yourscript.js?'+Math.random()+'"></script>');
</script>
...
</html>

Edit: In case this is not obvious, remove this code as soon you will go into production!

TheHippo
  • 61,720
  • 15
  • 75
  • 100
  • 2
    Only do this if you're developing, since caching is there to speed up page load times for good browsers. But then doing this will make it harder to come back and find, so maybe use a variable instead. – Aram Kocharyan Aug 12 '12 at 07:58
  • It really looks like hack and can be easily forgotten to remove it before bringing into production. – Igor Kustov Dec 03 '13 at 04:51
5

In order to set the browser cache turned off. Follow the instructions below:

MS IE

  1. from a menu select "Tools" for IE5 or "View" for IE4
  2. select "Internet Options"
  3. in "Temporary Internet Files" section click on "Settings"
  4. select "Every visit to the page" for "Check for newer versions of stored pages" save the settings I hope this may help please check
gmhk
  • 15,598
  • 27
  • 89
  • 112
  • 1
    For IE8 and IE9, go to Internet Options -> General tab. In the Browsing History section, click on the Settings button, and choose "Every time I visit the webpage" under the Temporary Internet Files section, then click OK. – furman87 Jan 06 '12 at 21:06
4

hit "Fn F12" to open developer tools

click Cache

choose "Always refresh from server"

Every time you refresh it should be clearing the cache, but there are also quick access cache clearing from the cache menu or the shortcuts that are active when the dev tools are open.

*Note- you must leave the dev tools window open, it doesn't have to be up front, but it has to remain open for the cache to remain disabled.

Mac
  • 41
  • 1
3

Ctrl+Shift+Del will open the Clear Private Data dialog (or select it from the Safety menu). Uncheck everything but the first two items to clear only the cache.

You shouldn't have to clear the cache though. If you access your js files through a web server (such as IIS running locally), the normal cache control mechanisms should do the trick. If they don't, a Ctrl+F5 usually fixes the problem.

josh3736
  • 139,160
  • 33
  • 216
  • 263
  • The problem is that in production we want the browser to use the cache as the javascripts are massive. Which cache control mechanism are you talking about? – Lydon Ch May 03 '10 at 03:04
  • I was talking about development and testing. HTTP's `Last-Modified`, `If-Modified-Since`, and `ETag` headers let the browser and server figure out whether a file has been modified, and if it has, update the browser's cached version. – josh3736 May 03 '10 at 03:41
  • Awesome, that worked! My problem was CSS not rendering when changed. `Ctrl + Shift + Del` was ***not*** working, however `Ctrl + F5` finally cleared the cache. – Ian Campbell Jul 05 '13 at 14:17
2

If your javascript files are served exclusivley from a sub-directory, you could enable immediate content expiration for that directory in IIS. I recently had this problem serving content from a sub-directory and this was the fastest, simplest solution that I found.

John Ingle
  • 1,490
  • 2
  • 11
  • 12
1

Open the IE debugging tools (F12), Cache on the menu, and select always refresh from server. This does mean you need to keep the debugging tools open.

Daniel Revell
  • 8,338
  • 14
  • 57
  • 95
0

Maybe a easier way not to have user refresh the browser is just to rename the js files (and css). This is what worked for me... as the server didn't like a random number after the .js file

Eugen
  • 1
  • 1
    Another hack is to just append a random *query string* to the end of the file (i.e. "http://mysite.com/myscript.js?random=B6646B155E" where random is a different value each time -- the server should ignore it, but the browser will avoid using a cached version.) This is useful when A.) you want to force ALL clients to get the latest script (not just your dev machine) and B.) you don't have access to server settings (such as when a page expires). – BrainSlugs83 Oct 12 '12 at 18:09