17

I have already set the option 'cache: true', but the cache seems only work in IE, but not in Firefox and Chrome. Is that a known issue?

silent
  • 3,964
  • 5
  • 27
  • 29

1 Answers1

37

The cache option isn't a special cache that jQuery maintains, so maybe it's a bit of a misnomer.

  • cache: false appends a timestamp to the URL being requested, so it forces the browser to grab a fresh copy, it's more of a cache-breaker.
  • cache: true does nothing, the native browser caching is left to do whatever it's going to do here.

It's not a jQuery specific thing at all, it's just how different browsers choose to cache a response or not. If your cache headers are set correctly telling the browser to cache it, then it should. However, IE likes to cache the hell out of requests even when there are no header instructions to do to...that's likely the behavior you're seeing. If it's the behavior you want though, add the cache control headers (see the link above) to your pages you want cached in other browsers as well.

laylarenee
  • 3,276
  • 7
  • 32
  • 40
Nick Craver
  • 623,446
  • 136
  • 1,297
  • 1,155
  • 1
    I think your booleans are backwards. `cache: false` adds the timestamp query string, while `cache: true` defaults to browser behavior. – RANGER Aug 30 '11 at 22:26
  • 1
    Why did the op accept the answer? I have the same problem with Chrome. No matter what I do I can't get a 304 for an ajax request even though the server sends Etag and Last-Modified headers correctly. I also get a 304 when requesting the URL directly from the address bar but not from ajax, so it's clearly not a server issue. –  May 31 '17 at 19:56