O
O
Onatskyi2018-05-28 21:32:01
JavaScript
Onatskyi, 2018-05-28 21:32:01

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

2 answer(s)
V
Vitaly Stolyarov, 2018-05-28
@Ni55aN

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.

A
Artem, 2018-05-28
@devspec

For example, so

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question