是否可以知道文件是否在用户的浏览器缓存中?
I am doing something like this: if an image is cached on user's computer and its timestamp is the same as the one on the server, then display the cached version; otherwise, do NOT load the image from the server.
我这样做:如果图像缓存在用户的计算机上,并且其时间戳与服务器上的时间戳相同,则显示缓存版本;否则,请勿从服务器加载图像。
I guess maybe JavaScript can do this, so I tagged this post as javascript. If it is improper, please help me to re-tag it.
我想也许JavaScript可以做到这一点,所以我将这篇文章标记为javascript。如果不合适,请帮我重新标记。
Edit: Here I give more details about what I am going to implement. I am working on something like a web-based file explorer, where thumbnails are loaded only if the user click on a "view thumbnail" button beside each image. If a thumbnail is already cached, use the cached version; otherwise, show a generic image icon.
编辑:在这里,我提供了有关我将要实施的内容的更多详细信息。我正在开发类似于基于Web的文件浏览器,只有当用户单击每个图像旁边的“视图缩略图”按钮时才会加载缩略图。如果已经缓存了缩略图,请使用缓存版本;否则,显示通用图像图标。
5 个解决方案
#1
0
A browser can send the "If-Modified-Since" and "ETag" headers to indicate to the server that it does have a version of a resource. Check the W3 caching rules regarding these headers.
浏览器可以发送“If-Modified-Since”和“ETag”标头,以向服务器指示它确实具有资源版本。检查有关这些标头的W3缓存规则。
You could query for those headers on the server, sending back the generic icon if not found, and a "304 Not Modified" response if found.
您可以在服务器上查询这些标头,如果找不到,则发回通用图标,如果找到,则返回“304 Not Modified”响应。
更多相关文章
- Javascript来自数据库的图像上的图像映射
- python 简单图像处理(2) 镜像
- caffe python批量抽取图像特征
- 在Python中显示来自控制台的图像
- Python为8bit深度图像应用color map
- 每次部署站点时,如何使用Google App Engine清除内存缓存?
- Tensorflow:恢复图形和模型,然后在单个图像上运行评估
- 在需要缓存的时候,谨慎使用python的负下标
- python的PIL绘制多行文本的图像。