7
Is it possible to find out, via Javascript and without any additional HTTP request, whether or not a particular resource is in the browser cache? And if you are, get it too without that requisition?
In my view, when the server sends a "long-term" resource (i.e. a header Expires
with a very high value) browser checks - in a second query - if this feature exists in its own cache and its validity has not expired yet, in which case no additional request is made. However, if such a feature is not found or is "expired", the request is made immediately - without giving the programmer a chance to cancel it.
I would like to have a little more control over this process: if the resource is in the cache, use it, otherwise adopt an alternative strategy. This would require a kind of Javascript API to query the state of the cache, I believe, and as far as I know this is not possible - since the browser abstract your programmer cache.
Is there anything - preferably cross-browsers - that meets this requirement? Or perhaps an alternative way to achieve the same result?
Note: I am not interested in solutions involving the local Storage - because that would require taking the resources that are already in cache and save (and manage) a copy of them in this already limited space.
Thanks for the suggestion, in fact it is not necessary to save the entire resource in the Storage location to have any benefit (if I save your URL and its expiration date I can tell if it can be cached). Unfortunately, it is a Russian roulette: if the cache is cleared before the time, the registration on the Storge site will not be notified, so I will end up doing yes the request I was trying to avoid. Anyway, +1, because at least this strategy reduces the overhead in relation to "no solution" - even if it is not a definitive solution.
– mgibsonbr