Is there a way in either Javascript or C# to tell if the browser that someone is using has disabled caching of static content?
I need to be able to test whether or not the browser is optimized for caching.
Is there a way in either Javascript or C# to tell if the browser that someone is using has disabled caching of static content?
I need to be able to test whether or not the browser is optimized for caching.
Another approach that involves client and server.
UPDATE
I did a bit more investigation of the problem and you can find more detailed answer in my recent post Note, the solution described below (initially) is not cross browser solution.
Not sure if it helps, but you can try the following trick: 1. Add some resource to you page, let's say it will be javascript file
cachedetect.js
. 2. The server should generatecachedetect.js
each time someone request it. And it should contain cache-related headers in response, i.e. if browser's cache is enabled the resource should be cached for long time. Eachcachedetect.js
should look like this:After that you can simply check for
cacheEnabled === true
orcacheEnabled === false
after some period of time.I believe this should work: http://jsfiddle.net/pseudosavant/U2hdy/
Basically you have to preload a file twice and check how long it took. The second time should take less than 10ms (in my own testing). You will want to make sure the file you are testing is sufficiently large that it takes at bit to download, it doesn't have to be huge though.