I am using a JavaScript script that tells me if specific image URLs are cached in the user's browser cache. I'm using this because I build an array of non cached images that will be loaded separately, after more important process is done. This script is wrote specifically for Google Chrome so I don't need a cross-browser solution.
My current function checks the time spent loading the image and if it is less than a few milliseconds (currently 25ms), I assume it is pulled from cache.
The difference between cached and not cached images is easy to spot manually by checking the Resources Panel in Chrome's Developers Tool. When hovering the loading time, Chrome tells if file was pulled from cache or not by printing a tool-tip looking like this: xx ms Latency, xx ms Download (from cache)
.
I noticed that on some occasions, the Latency time is quite long (e.g. 64ms for only 2ms downloading time) and makes my detect function useless as the total loading time then exceeds my threshold. Increasing the threshold is not possible as small and not cached images could also be loaded in the same amount of time.
Now that you got my problem, here goes my question:
-Is it possible to check in a 100% accurate way (e.g. like chrome's resources panel) that file comes from cache ? (I guess if that panel does it, there has to be a way but I couldn't find it on the Internet)
Or
-Is there a way to separate the two delays (i.e. Latency vs. Download) to be able to check only the true downloading time ? Calculating time spent between starting the load of the image and the onload
event returns the total amount of time.
I thank you for reading my question and even if you don't have a precise solution, thoughts, ideas, are most welcome !
(PS: I am not a native english speaker so please don't blame me for doing mistakes !)
Gaël