silent
silent

Reputation: 4014

The cache option of jQuery .ajax doesn't work in Firefox and Chrome?

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?

Upvotes: 17

Views: 9284

Answers (1)

Nick Craver
Nick Craver

Reputation: 630607

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.

Upvotes: 37

Related Questions