Answer the question
In order to leave comments, you need to log in
How to check if an image is in the browser cache?
Good afternoon! Tell me, is it possible to check if the image was cached by the browser?
I want the pictures that are loaded to appear after loading smoothly. And those pictures that were already cached - appeared instantly. How can this be implemented? Thanks in advance!
Answer the question
In order to leave comments, you need to log in
Not at all https://stackoverflow.com/a/22232012
If a definition with some probability is enough, then this option is fine (check Disable cache and press any key to check in Network)
The idea is this: calculate the ratio of the image load time to its size, and if the result is less than 2% (ms/size * 100), then consider that the image was taken from the cache, since it loaded too quickly
. In my case, < 0.02 is fine, but everything may depend on hardware and network.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question