06 Oct 2010

Internet Explorer 9 is fast, really, really fast! A lot of that speed comes from the massive caching improvements in IE9 – but this is a bit of a double edge sword, especially for developers when caching gets in the way of what is actually happening. I spent two hours debugging an odd caching issue recently and this is the sad story.

For some testing I needed to setup a redirect, in this case a 301 permanent redirect (handy HTTP status codes cheat sheet in case you don’t remember these). What this would do is enable me to have site alpha (http://localhost:5000/Demo) redirect to site beta (http://localhost:9000/Demo).

Prior to this the scenario look like this:

image

Behind the two browser windows is the IE 9 Developer tools and their fantastic new network capture feature. You can easily see that when I hit site alpha I got a 200 result, meaning all good and it loaded.

Once I setup the redirect, you’ll see I get a 304 this is because the data is already cached. Note that even though I typed in the site one URL it immediately loaded site two. This is because the browser had cached the redirect and so skipped the network steps for performance.

image

Now the problem, I wanted to turn off the redirect – however the browser cached it and so would ignore the change. Clearing cache, deleting files, rebooting and even using the IE reset option did nothing to solve this Crying face 

The only way to fix it was to fire up the fantastic Fiddler tool and use it’s Clear Cache option with the option to delete persistent cookies, which flushes the WinINET cache.

image

Considering that this is supposedly the same as clearing the IE cache I have no idea why this works and IE cache clearing doesn’t but it does work.

Comments

Dario  Mratovich's picture

Hi Robert This is a good tip for clearing the host cache if you fall into this trap but I'd suggest being very careful with permanent redirects. To ensure that you don't fall into this trap. Can you imagine what would happen in production if you made a mistake? You'd have to get all your users to install Fiddler to clear their caches :-) (by the way the HTTP status code for a permanent redirect is 301, not 302) If you're using a permanent redirect (i.e. status code 301) you're telling browsers "hey, the things you're looking for has moved to a new location - PERMANENTLY". Internet Explorer (and I'm sure other browsers that implement RFC 2616) take this literally and will cache the redirect response to minimize a network round-trip. You could force a 301 redirect not to be cached by including the "Cache-Control: no-cache" header in the response. If there's a chance that you'll need to change a redirect (i.e. it won't be permanent) then I'd recommend using temporary redirects (status code 302), which will obey caching control headers like "Cache-Control: max-age=200".
Robert MacLean's picture

Thanks for pointing out the redirect code, fingers failed me there. More important thanks for the great info on caching - that is really valuable knowledge!
 Twitter Trackbacks for Redirected down a one way: Clearing's picture

[...] Redirected down a one way: Clearing the Internet Explorer host redirect cache | SADev sadev.co.za/content/redirected-down-one-way-clearing-internet-explorer-host-redirect-cache – view page – cached Internet Explorer 9 is fast, really, really fast! A lot of that speed comes from the massive caching improvements in IE9 – but this is a bit of a double edge sword, especially for developers when caching gets in the way of what is actually happening. I spent two hours debugging an odd caching issue recently and this is the sad story. For some testing I needed to setup a redirect, in this case... Read moreInternet Explorer 9 is fast, really, really fast! A lot of that speed comes from the massive caching improvements in IE9 – but this is a bit of a double edge sword, especially for developers when caching gets in the way of what is actually happening. I spent two hours debugging an odd caching issue recently and this is the sad story. For some testing I needed to setup a redirect, in this case a 301 permanent redirect (handy HTTP status codes cheat sheet in case you don’t remember these). What this would do is enable me to have site alpha (http://localhost:5000/Demo) redirect to site beta (http://localhost:9000/Demo). Prior to this the scenario look like this: Behind the two browser windows is the IE 9 Developer tools and their fantastic new network capture feature. You can easily see that when I hit site alpha I got a 200 result, meaning all good and it loaded. Once I setup the redirect, you’ll see I get a 304 this is because the data is already cached. Note that even though I typed in the site one URL it immediately loaded site two. This is because the browser had cached the redirect and so skipped the network steps for performance. Now the problem, I wanted to turn off the redirect – however the browser cached it and so would ignore the change. Clearing cache, deleting files, rebooting and even using the IE reset option did nothing to solve this   The only way to fix it was to fire up the fantastic Fiddler tool and use it’s Clear Cache option with the option to delete persistent cookies, which flushes the WinINET cache. Considering that this is supposedly the same as clearing the IE cache I have no idea why this works and IE cache clearing doesn’t but it does work., Redirected down a one way: Clearing the Internet Explorer host redirect cache View page Tweets about this link [...]
Internet Explorer 9 breaks with localhost | SADev's picture

[...] Explorer 9 works great, except when it doesn’t, and it seems to not work for developers more than most, or maybe it’s just me (could the IE9 team [...]
Justin Grant's picture

Hi Robert - I posted a reply onto the Fiddler Google Group thread you linked to above. I'll be curious to know what Eric Lawrence (who not only is the author of Fiddler but, AFAIK, is involved with IE's own caching work) thinks of the problem you found. Out of curiosity (and to provide better repro steps) what specific IE cache-clearing options did you try? Did you try to delete *everything* via the IE UI (including history, cookies, etc.) or did you only delete Temp Internet Files via IE's UI?
Robert MacLean's picture

I tried *everything* in IE 9
Eric Lawrence's picture

As you noticed, IE9 Beta has a known bug where redirect cache entries are not properly cleared by the IE UI option. This will be fixed in later releases. Thanks for the post!
Robert MacLean's picture

Thanks for the info - do know what the connect item is for this bug so I can vote on it?
Eric Lawrence's picture

I do not know if there's a bug on Connect. However, the issue is already in the internal tracker, and this isn't the sort of regression that we could ship with. Thanks for your interest!
Wayne Ye's picture

Hi Robert, Thank you for the good catch and solution, I encountered a same problem (IE9 RC redirects localhost to an IP Address), I found your article from Google, thanks:) Cheers, Wayne's Geek Life http://WayneYe.com
Visitor's picture

I have same problem with IE8. I want disable access to "www.google-analytics.com" for my PC. I did "everythin" and even more to clear 301 redirection for this address from my PC to "www.google.com/analytics/". Also modifying the "hosts" file don't help! Only replacing "google-analytics.com" by filtering whole traffic with Proxomitron helps. I hope Fiddler tool can do it better!
Matt Bradley's picture

It looks like Firefox 5.0 is now doing the same thing:

http://www.inventpartners.com/content/firefox-5-redirect-bug-pragma-no-c...

Matt Bradley's picture

For web application developers, it seems the fix (in FF5.0 at least) is to make sure that your application sends the following header: Cache-Control: no-cache Otherwise, it is possible that your application is sending headers which tell the user agent that it can cache the redirect.
Deleting Persistent Cookies | Pafos Photos's picture

[...] delete persistent cookies, sadev.co.za [...]
rwec.co.uk » Cached Redirects Considered Harmful ('s picture

[...] even once you've figured it out, it's not that obvious what to do about it - do you do a deep clean of the browser's cache every time something's not quite right? I see a sledgehammer approaching a nut. And if you've released your mistake to a non-technical [...]
Adnan's picture

I found solution for IE9's permanent cached in redirection issue: - Open IE9 and press Ctrl+Shift+P for private browsing - Navigate to the problem URL - Then go back to normal browsing and all should be fine again
Chris's picture

http://support.microsoft.com/kb/234067/EN-US I had an issue that I actually had to tell IIS to stop caching my applications
Rory's picture

Adnan, That is brilliant, amazing how the small & unusual things can work so easily. Thanks again. Rory.
Lucian Maran's picture

Thank you Adnan! Your solution works for IE10, too.
Craig's picture

Thanks Robert, this has just saved me hours of trawling round the web looking as to reasons why I could not load the page I wanted too.
Tomaso's picture

To tell browser not to cache 301 redirect, I used this header: Cache-Control: no-store, no-cache, must-revalidate The browsers really ask again where to redirect. I just wonder if Google will still transfer PageRank for this type of 301 Permanently moved, which is really not permanent.
josephbrown's picture

Thanks for this post, i will try that.
Visitor's picture

Thank you so much for this article. I have been scratching my head and spend hours wondering why my pages doesn't load. It's only 2 am :|!!

Add new comment

dontclickme