1

I have a javascript galleria which does work in every modern browser, even in IE7. But in IE8 if its load.. it does not show the gallery.. BUT if I press Ctrl + F5 it does a hard reload, it erase the cache and finally the galleria appears.. If I just reload the page.. or if I go to another page with the same galleria script, the problem comes again.. so I need a hard reload script for IE8.

Pseudo Code:

On Document Load

If user agent IE8 {
erase website cache
}

do normally continue webpage loading..
Tomkay
  • 5,120
  • 21
  • 60
  • 92
  • 1
    Why do you want to do this? User agent sniffing is nearly always wrong. What problem are you actually trying to solve? – Craig Stuntz Jan 13 '11 at 15:02
  • I have a javascript galleria which does work in every modern browser, even in IE7. But in IE8 if its load.. it does not show the gallery.. BUT if I press Ctrl + F5 it does a hard reload, it erase the cache and finally the galleria appears.. If I just reload the page.. or if I go to another page with the same galleria script, the problem comes again.. so I need a hard reload script for IE8. – Tomkay Jan 13 '11 at 15:05
  • 1
    and why not trying to ask for a solution about this (the **real**) problem?! – ifaour Jan 13 '11 at 15:08
  • im just a bit confused.. because IE7 does it well. IE8 bitches me. And the galleria-script is not easy to debbug, specially for me as a novice skilled javascript programmer. – Tomkay Jan 13 '11 at 15:16
  • 2
    ifaour and Craig are right, You usually want to mention your problem. Suggesting possible solutions is ok, but many times the solution you've thought of is just not very good. In this case, you should figure out why IE8 is not the page when things are cached. How about adding a link to a test version? Even better, a reduction of the problem? I often find that the answer myself as I create the simplest possible reduction of a problem. – Ruan Mendes Jan 13 '11 at 15:17
  • To Mods or OP, please edit your question and add your first comment to the question body. – ifaour Jan 13 '11 at 15:34

4 Answers4

3

The problem isn't on the client side. The problem is your server. IE will aggressively cache responses to AJAX requests unless the server sets a Cache-Control: no-cache in the response. Clearing the cache in the browser is the wrong fix, because the server should decide what is current and what is not.

So change the server response to your request to include the correct headers.

Craig Stuntz
  • 125,891
  • 12
  • 252
  • 273
  • But then, how come it's a one browser issue? – ifaour Jan 13 '11 at 15:33
  • @ifaour, because IE has a different, default policy for caching AJAX requests in the case where the server does not provide a `Cache-Control` header than either Firefox or Chrome does. Not sure about Safari or Opera. – Craig Stuntz Jan 13 '11 at 15:53
0

see that link about clearing the cache! Clear all website cache?

Community
  • 1
  • 1
Arthur Neves
  • 11,840
  • 8
  • 60
  • 73
0

One possible way to fake a clear cache would be to attach a cache buster to all resources from a page your resources like

"test.js?cacheBuster=" + new Date())

This should be a last resort.

Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
-1

Using javascript you won't be able to do this. What you can do is to write code in your server side language so that the entire page won't be cached.

rahul
  • 184,426
  • 49
  • 232
  • 263