IE 和 Chrome 缓存“无缓存”图片
您好,我在 Rails 应用程序中广泛使用片段缓存。我已经缓存了其中包含用户图像的片段。因此,当用户更改他/她的头像(图像)时,很多片段必须过期。为了解决这个问题,我做了一些设置,以便用户的头像 URL 始终保持不变(“/avatars/:user_id/thumbs”)。
我使用亚马逊 s3 进行存储,图像的过期标头是“无缓存”。 示例图像 URL : https://s3.amazonaws.com/bucket_name/avatars/388/thumbs
在 IE 和 Chrome 中,我面临一个特殊的问题。当用户更改头像时,不会立即反映在客户端。图像需要刷新 2-3 次页面才会发生变化。以前有人遇到过类似的问题吗?
Hi I'm using fragment caching extensively in my rails application. I've cached fragments which have user images in them. So when a user changes his/her avatar(image), a lot of fragments have to be expired. To solve this, I've made some settings so that a user's avatar URL is always constant ( "/avatars/:user_id/thumbs" ).
Im using amazon s3 for storage and the expires header for the images is "no-cache".
Sample image URL : https://s3.amazonaws.com/bucket_name/avatars/388/thumbs
In IE and Chrome, Im facing a peculiar problem. When a user changes his avatar, it is not reflected immiediately on client side. It takes 2-3 page refresh for the image to change. Has anyone faced similar issues before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你的处理方式是错误的。使片段过期,但允许 Rails 的缓存清除时间戳强制浏览器下载新图像。
例如 s3.amazonaws.com/bucket_name/avatars/388/thumbs/filename.jpg?1230601161
You're going about this the wrong way in my opinion. Expire the fragment as you're doing but allow rails' cache busting timestamps to force the browser to download new images.
e.g. s3.amazonaws.com/bucket_name/avatars/388/thumbs/filename.jpg?1230601161