停止在Rails和浏览器中缓存图像? [英] Stop images from caching in Rails and browser?

查看:60
本文介绍了停止在Rails和浏览器中缓存图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个图像裁剪工具,可以单击该图像并将其裁剪,然后将新裁剪的图像保存在旧的裁剪图像上,然后重定向回显示该图像的原始页面.

I have created a image crop facility that I can click on an image and crop it and it saves the new cropped image over the old one, then redirects back to the original page where the image was show.

但是即使重定向后它仍然显示旧图像,并且直到我刷新页面后才显示新图像.

But it still shows the old image even after a redirect and doesn't display the new one till I refresh the page.

我尝试仅使用图像标签并在图像后删除资产时间戳,但它仍显示旧图像,并且我还尝试添加元标签以停止浏览器缓存,但不起作用.

I have tried just using an image tag and removing the asset timestamp after the image but it still displays the old image and I have also tried adding meta tags to stop browser caching but not working.

如何解决此问题而无需刷新页面?

How can I solve this without having to do a refresh page?

推荐答案

这可能不是最好的方法,但是我过去已经通过使用JavaScript将时间戳附加到图像URL来解决了这个问题:

It's probably not the best way, but I've solved this problem in the past by simply appending a timestamp to the image URL using JavaScript:

http://www.mysite.com/img/some_image.jpg?timestamp=12342312412

下次加载时,时间戳记设置为当前时间,并且URL不同,因此浏览器对图像进行GET而不是使用缓存的版本.

Next time it loads, the timestamp is set to the current time and the URL is different, so the browser does a GET for the image instead of using the cached version.

这篇关于停止在Rails和浏览器中缓存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆