Skip to content Skip to sidebar Skip to footer

How To Force Chrome Not To Reload Images With Same Url Till The Page Is Refreshed ,like Firefox

Firefox doesnt reload images with the same url till refresh. $('#a').click(function(){$('#img').attr('src','img.php?id=3');}); //the two li

Solution 1:

Use this;

<script>var randomNumber = Math.random();

$("#a").click(function(){$("#img").attr("src","img.php?id=3&rand=" + randomNumber);});
</script><imgid="img"src="img.php?id=3&rand="<script>document.write(randomNumber)</script>>

This will always generate different url. You dont needt to handle rand at the backend php

Solution 2:

Browser behavior is unique to individuals' browsers. Some people have set their browsers to save history and thus cache, other have not.

You can encourage or discourage caching by setting the headers on the page as seen here:

http://www.php.net/manual/en/httpresponse.setcachecontrol.php

Note, this is over-ridden by local browser settings.

Also, by creating a url that does not include a querystring eg:

http://www.mydomain.com/myimage3/ vs. http://www.mydomain.com/image.php?id=3

You "may" have better luck encouraging caching in the browser, though that my no longer be the case as it once was.

(frameworks such as zend and codeigniter offer url structures without querystrings in an easier to deploy format)

Post a Comment for "How To Force Chrome Not To Reload Images With Same Url Till The Page Is Refreshed ,like Firefox"