图像重新加载原型 if-modified
我在客户端使用原型。
我需要更改页面上的图片而不重新加载。因此,在我的 .js 文件中,我更改了图片的 src,它工作正常。但我还需要,如果请求相同的图像,它还会请求服务器知道该图像是否已更改,并在需要时重新加载。服务器发送 Last-Modified 标头,如果获得 if-modified-Since,则进行检查,并发送新图像或 304 Not Modified 响应。
当第一次请求图像时,服务器会回复一个图像。 第二次给出 304 Not Modified。 但是当我尝试重新加载 3-d 时间时,它根本不会触发任何请求。并且显示相同的缓存图像。
如果在发送未修改的响应之前,它是否是原型的某些功能,它不会请求。还是还有其他原因?
有什么办法可以强制它提出请求吗?
在 Firefox 和 Chrome 中测试
I use prototype on the client side.
I need to change picture on the page without reloading. So in my .js file I change the src of a picture and it works ok. But I also need that if the same image requested, it would alse request the server to know if this image has changed, and reload if needed. Server sends last-modified header, and if gets if-modified-Since, then checks, and either sends new image or 304 Not Modified response.
When the image is requested the first time, server replies with an image.
Second time gives 304 Not Modified.
But when I try to reload 3-d time, it won't trigger any request at all. And the same cached image is shown.
Is it some feature of prototype, that it won't request, if before NOT MODIFIED repsonse was sent. Or any other reasons?
Is there any way to force it to make a request?
Tested in Firefox and Chrome
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个常见问题,您需要添加随机更改图像的额外 id - 这样它就会更新内容。
我一直在研究验证码图像验证,需要将图像更新为后端实际执行的操作。在它缓存图像之前,会话值会有所不同。
因此,在 HTML 中,我添加了一个变量,然后随机生成一个数字并更改值,因此理论上没有缓存。
您应该能够找到 JavaScript 随机数生成器并将其添加到任何图像中,并且 id= 可以是您喜欢的任何内容,因为它只是为了欺骗服务器和浏览器缓存。
反正也一直在写图片内容替换
This is a common problem you need to add extra id that randomly changes to the image - this way it updates the contents.
I been working on a captcha image verification which needs to update the image to what it has actually done on backend. Before it would cache an image and session value would be different.
So in HTML I add a variable which I then randomly generate a number and change value so there is no cache in theory.
You should be able to find JavaScript random number generators and add this to any image and id= can be anything you like since it just to fool the server and browser caching.
Anyways have also been writing image content replacement