Can I find out if the file is in the user's browser cache?

I am doing something like this: if the image is cached on the user computer and its timestamp is the same as on the server, then display the cached version; otherwise DO NOT upload the image from the server.

Maybe JavaScript can do this, so I marked this post as javascript. If this is not correct, please help me relabel it.

Edit: Here I will talk more about what I am going to implement. I’m working on something like a web file explorer where thumbnails are downloaded only if the user clicks the “view thumbnail” button next to each image. If the sketch is already cached, use the cached version; otherwise, display a common image icon.

+3
source share
5 answers

The browser can send "If-Modified-Since" and "ETag" headers to indicate to the server that it has a version of the resource. Check out the W3 Caching Rules for these headers.

, , , "304 Not Modified", .

0

.

" ". , , , .

, , , . , . , -, ?

, , , .

  • " "
  • " ", ( , script , , )
+1

RSS, , , . . , , .

? , , , . -, , , .

+1

, . . , . , HEAD.

0
source

Could you just move / delete / rename it on the server? Then handle the broken image with javascript Image.onError to hide the broken image tag for people who don't have a cached image.

I think this will show a cached version for those who did this on their bracelet. The rest of the people will do nothing

0
source

Source: https://habr.com/ru/post/1772052/


All Articles