NYCPHP Meetup

NYPHP.org

[nycphp-talk] Prevent (IE) browser cache of image

Jakob Buchgraber jakob.buchgraber at googlemail.com
Sun Apr 8 05:59:05 EDT 2007


Aaron Fischer wrote:
> Using time() to add a unique string to the img src seems to work quite 
> well, thanks!
>
> I think I prefer this to the nocache solution which gets applied to 
> all page elements.
>
> This example will only prevent caching of the one image, so all other 
> items on the page can be cached, which I don't mind.  Will help the 
> page load faster, particularly beneficial for users on a slower 
> connection.
>
> Cheers,
>
> -Aaron
>
>> Just add a unique string to the URL of the image
>>
>> <img src="createImg.php?<?php echo time(); ?>" />
>>
>> So the URL of the string changes every time the user reloads the page
>>> How can I force IE to load a fresh version of the image, either via 
>>> PHP or HTML/HTTP code?
>>>
>>>
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
As far as I understood the HTTP No-Cache Solution you should include 
this file in the Script that generates the image.

<?php
// createImg.php

require "nocache.php";

header ("Content-Type: image/jpeg");

imagejpeg (..);
?>

So this actually should only prevent the createImg.php from being 
cached. I am not quite sure whether this works with IE, tough. This 
browser seems to have some http caching related bugs.

Cheers,
Jay

-- 
Join Linuxfriendlyhardware.org project on irc.freenode.org#lfh (german)
Registered Linux User #373457




More information about the talk mailing list