图像重新加载原型if-modified [英] Image reload prototype if-modified

查看:190
本文介绍了图像重新加载原型if-modified的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户端使用原型。

我需要在不重新加载的情况下更改页面上的图片。所以在我的.js文件中,我更改了图片的src,它运行正常。但我还需要,如果请求相同的图像,它还会请求服务器知道此图像是否已更改,并在需要时重新加载。服务器发送最后修改的头,如果获得if-modified-Since,则检查,并发送新图像或304 Not Modified响应。

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.

请求图像时第一次,服务器回复图像。
第二次给出304 Not Modified。
但是当我尝试重新加载3-d时,它根本不会触发任何请求。并显示相同的缓存图像。

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.

原型的一些功能,如果在发送NOT MODIFIED repsonse之前它不会请求。或任何其他原因?

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?

在Firefox中测试过和Chrome

Tested in Firefox and Chrome

推荐答案

这是一个常见的问题,您需要添加随机更改为图像的额外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.

所以在HTML中我添加一个变量,然后我随机生成一个数字并更改值,这样就没有缓存了理论上。

So in HTML I add a variable which I then randomly generate a number and change value so there is no cache in theory.

Image?a=5291

if static image image.jpg?id=[blah]

您应该能够找到JavaScript随机数生成器并将其添加到任何图像并且id =可以是你喜欢的任何东西,因为它只是为了欺骗服务器和浏览器缓存。

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


<img id=reli src yourimg.jpg?a=5829>

  //--------------------------------------------------------------------------|
  // Javascript to update image content without reloading page 
  // http://www.pro.org.uk
  // Feel free to re-use leaving this intact 
  // contact me: http://www.pro.org.uk/classified/Directory?act=contact
  //--------------------------------------------------------------------------|
   function ChangeLanguage(lang) {
     langu="1&lang="+lang; 
      if (document.getElementById('reli').src.indexOf("country")>0) {
       document.getElementById('reli').src=document.getElementById('reli').src.substring(0,document.getElementById('reli').src.indexOf("country")-1);
     } else if (document.getElementById('reli').src.indexOf("lang")>0) {
       document.getElementById('reli').src=document.getElementById('reli').src.substring(0,document.getElementById('reli').src.indexOf("lang")-1);
     }
     document.getElementById('reli').src=document.getElementById('reli').src+langu;
  }
  function ChangeCountry(country){
    cc="1&country="+country;
    if (document.getElementById('reli').src.indexOf("lang")>0) {
       document.getElementById('reli').src=document.getElementById('reli').src.substring(0,document.getElementById('reli').src.indexOf("lang")-1);
    }
    document.getElementById('reli').src=document.getElementById('reli').src+cc;
  }
 

这篇关于图像重新加载原型if-modified的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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