Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fool Proof "Prevent Caching" 1

Status
Not open for further replies.

dkdude

Programmer
Jun 16, 2003
849
DK
Hi there,

PROJECT

I have a PHP based site where the admin creates a product in 5 steps. In the first step(s) the user will select/upload a thumbnail and a larger picture.

The pictures are renamed to match the product name with an addition of -thumb or -pic before the file extension. Example:

[tt]thisProduct-thumb.gif[/tt] and [tt]thisProduct-pic.jpg[/tt]

Works fine.

When the user changes/uploads new thumbnail/picture in later steps the file is uploaded and renamed.

Works fine.

PROBLEM

The file is replaced, but remains in the browser cache (IE6) because the name is the same as before the picture(s) were replaced.

Well, actually, the thumbnail image does change in the browser - probably because of it's small size. The bigger image just won't. Tried putting in the address of the picture in the browser address line, then pressing Ctrl-F5 to force a reload -THEN the right (new) picture is displayed...

Must be something about the cache control in the HTML HEAD section, I recon.

I've tried:

Code:
  <META HTTP-EQUIV=&quot;CACHE-CONTROL&quot; CONTENT=&quot;NO-CACHE&quot;>
  <META HTTP-EQUIV=&quot;expires&quot; CONTENT=&quot;0&quot;>
  <META HTTP-EQUIV=&quot;PRAGMAS&quot; CONTENT=&quot;NO-CACHE&quot;>
without any success...

Any suggestions?

Many thanks


Jakob

dkdude1.gif
 
Jakob,

You could, after each upload, insert a random parameter on the end of the image SRC, something like:

<IMG SRC=&quot;images/myImage-pic.jpg?myRandNum=xxxx&quot;>

Where xxxx is generated randomly each time the image is uploaded/displayed.

I'm not sure if you have any server-side code available to you, but if so, this might work.

Hope this helps!

Dan
 
Try this instead:
<META HTTP-EQUIV=&quot;Expires&quot; CONTENT=&quot;-1&quot;>

Ad if you use ASP:
<% Response.CacheControl = &quot;no-cache&quot; %>>
<% Response.AddHeader &quot;Pragma&quot;, &quot;no-cache&quot; %>
<% Response.Expires = -1 %>

Also there are some that recommend to add this in between your </body> and </html> tags. (This is at the end of your html-files):
<HEAD>
<META HTTP-EQUIV=&quot;PRAGMA&quot; CONTENT=&quot;NO-CACHE&quot;>
</HEAD>
And some even recommend to put all three META tags in there as well.

__________________________
Corey

 
Thanks a million, Dan!

Fastest response I ever had!!

Added a random number after the image file name (in my PHP code) like you suggested:

Worked perfect

What can I say ... it fooled IE. Truely fool proof!

Now I can finish up before Christmas. Nice!

Merry Christmas and a star goes out to you

Best Regards


Jakob

dkdude1.gif
 
Thanks Corey,

And Merry Christmas to you too


Jakob

dkdude1.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top