Geekzone: technology news, blogs, forums
Guest
Welcome Guest.
You haven't logged in yet. If you don't have an account you can register now.


59 posts

Master Geek
+1 received by user: 1


Topic # 31797 31-Mar-2009 09:10
Send private message

I've got one image on this website which is dynamically generated (ie: <img src="my_dynamic_image.asp" />) but it looks like it's caching for some people, so they aren't seeing the newest version of it all the time

Is there a way to set this one file to not be cached?


Thanks!

Create new topic
BDFL - Memuneh
61521 posts

Uber Geek
+1 received by user: 12241

Administrator
Trusted
Geekzone
Lifetime subscriber

  Reply # 204354 31-Mar-2009 09:19
Send private message

Since this is a dynamic page, couldn't you add something like a GUID to the end of its name as a parameter, such as my_dynamic_image.asp?v=[GUID]...

This way the browser will see each request as a different one, always...






59 posts

Master Geek
+1 received by user: 1


  Reply # 204359 31-Mar-2009 09:34
Send private message

freitasm: Since this is a dynamic page, couldn't you add something like a GUID to the end of its name as a parameter, such as my_dynamic_image.asp?v=[GUID]...

This way the browser will see each request as a different one, always...

It's not really an option, the site is using an off the shelf shopping cart which I'm reluctant to change the code of (although I've just found that my customer doesn't seem so restrained in changing my code Yell)

I've just added...

    <meta http-equiv="cache-control" content="no-cache" />
    <meta http-equiv="pragma"        content="no-cache" />
    <meta http-equiv="expires"       content="0" />

... to the head of the pages containing the dynamic image which should stop the whole pages from being cached, but if there were a way to localise that to a single file that'd be ace

Phil Gale
1107 posts

Uber Geek
+1 received by user: 44

Trusted
Red Jungle
Subscriber

  Reply # 204376 31-Mar-2009 11:16
Send private message

I would use the method Mauricio outlined as it's the most reliable. Add a random guid or timestamp parameter to the image URL.




Red Jungle: we make fantastic software

RSS  Twitter  Facebook  Skype

BDFL - Memuneh
61521 posts

Uber Geek
+1 received by user: 12241

Administrator
Trusted
Geekzone
Lifetime subscriber

  Reply # 204378 31-Mar-2009 11:17
Send private message

Fair enough although adding a GUID as a parameter to that dynamically generate image would be one additional line and one change to the output - less than your changes I think...




61 posts

Master Geek


  Reply # 204379 31-Mar-2009 11:18
Send private message

If you don't want to change the code, then you could do a slight variant of what Mauricio is proposing.

Assuming you can put a proxy of some sort in front of the website (Squid perhaps?) and also assuming that the URI you're trying to prevent caching on is constant then you could put a rule in to rewrite any occurence of the URI and append to it ?v={timestamp}.

Not as nice as Mauricio's suggestion but might work


BDFL - Memuneh
61521 posts

Uber Geek
+1 received by user: 12241

Administrator
Trusted
Geekzone
Lifetime subscriber

  Reply # 204380 31-Mar-2009 11:19
Send private message

set TypeLib = Server.CreateObject("Scriptlet.TypeLib")
?version=[% =left(cstr(TypeLib.Guid),38) %]
set Typelib = nothing






mjb

922 posts

Ultimate Geek
+1 received by user: 21

Trusted

  Reply # 204443 31-Mar-2009 15:39
Send private message

teamsteve: I've just added...

???
???
???

... to the head of the pages containing the dynamic image which should stop the whole pages from being cached, but if there were a way to localise that to a single file that'd be ace


You want to send extra headers before the image in the dynamic image page. not sure how you do it in asp (getting hives here), but in php it's:

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // (Just an old date)





contentsofsignaturemaysettleduringshipping


mjb

922 posts

Ultimate Geek
+1 received by user: 21

Trusted

  Reply # 204444 31-Mar-2009 15:40
Send private message

Oh look.... here it is: http://support.microsoft.com/kb/234067.

So, you want asp code:

<%
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
%>




contentsofsignaturemaysettleduringshipping


Create new topic

Twitter »

Follow us to receive Twitter updates when new discussions are posted in our forums:



Follow us to receive Twitter updates when news items and blogs are posted in our frontpage:



Follow us to receive Twitter updates when tech item prices are listed in our price comparison site:



Geekzone Live »

Try automatic live updates from Geekzone directly in your browser, without refreshing the page, with Geekzone Live now.



Are you subscribed to our RSS feed? You can download the latest headlines and summaries from our stories directly to your computer or smartphone by using a feed reader.

Alternatively, you can receive a daily email with Geekzone updates.