I’m using the third party jsonp library for jquery. In the call to it, you can set cache to true.
However, upon checking in a HTTP sniffer, it appears that all requests are still being sent to the server..
This with the picasa, flickr, and youtube API.
What could be causing this behavior? It does not appear to be browser-specific as I have tested it in multiple browsers and all behave the same (not caching).
The URLs called don’t change from one request to the other and the call looks like this:
$.jsonp({
url: url,
cache: true,
async: false,
dataType: 'jsonp',
data: $.extend({ url: options.dataUrl, method: lookupData.method }, fixedOptions),
callbackParameter: "jsoncallback",
success: function(data)
{
$.extend(datasourceOptions, lookupData.onData(data));
getData();
}
});
The only “weird” thing about my setup is that the script that will call the .jsonp is included via a .ajax call itself.. Could that be the issue here? Sounds far fetched but…
Thanks,
Wesley
Edit: Ok, 3 out of the 4 have Expires headers set..
However, the fourth does not and only has these:
Cache-Control: private
Vary: Accept-Encoding
Access-Control-Allow-Origin: *
Connection: close
(this is flickr)
What’s going on there?
Also, is it not possible to override the header caching directives via jquery somehow?
I expect that the services you’re calling are returning cache control headers that tell the browser not to cache the response / to expire the cached response very quickly. You should be able to see them in the HTTP messages. Look for
Cache-Controland/orExpires, that sort of thing.Re your edit:
I don’t think so, no, certainly not with JSON-P, which is at its heart a
scriptelement being added to the page, so programmatic control over that is going to be extremely limited. Even if it were XHR, frankly, I don’t think there’s a way to tell the browser to use a cached version that’s stale according to its source.If this is happening within the page lifecycle, you could cache the result yourself in an object on the page, but I’m guessing you’re talking about caching between visits to the page (though I can’t immediately see why you want to defeat the origin’s definition of fresh/stale).