Jump to content

How could I prevent image caching?


9999

Recommended Posts

I have this code I want to give users to display on their websites or myspace pages.  Its bascically some images.  However, the content of one of the images changes daily even though its name will remain the same.

 

<TABLE border=1>
<TR><TD><IMG border=0 src="http://www.mysite.com/image1.gif"></TD></TR>
<TR><TD><IMG border=0 src="http://www.mysite.com/image2.gif"></TD></TR>
<TR><TD><IMG border=0 src="http://www.mysite.com/image3.gif"></TD></TR>
<TR><TD><IMG border=0 src="http://www.mysite.com/image4.gif"></TD></TR>
<TR><TD><IMG border=0 src="http://www.mysite.com/image5.gif"></TD></TR>
</TABLE>

 

Is there some simple code or script that I can include with my code to either prevent the images from caching and/or force a visitors browser to load current images?

 

Thanks

Link to comment
Share on other sites

you cannot use javascript on myspace and if you are not using server side language to create the image (if your using a static image) and you cannot use a meta tag on myspace; then you cannot prevent image cacheing. If your not using dynamic images instead of static images and you cannot use code to control a site/page; then you really do not have any option. Because I know myspace does not allow JavaScript or Meta tags or Server Side Language; so your out of luck there.

Link to comment
Share on other sites

Just add a paramater that you change daily (like the date):

 

src=http://..../image1.gif?nocache=20071205

 

Whenever you change this param, the browser will be forced to get the new image.

 

 

that would be allot of work and ineffective if you could not access the site someone else owned; that you had these pictures on. dynamic image - server side; is your best bet for this situation.

Link to comment
Share on other sites

Ok, sorry for not responding last week, I was out of town.

 

I have created and uploaded 365 images (one for each day of the year).

 

I name my orginal images like this: "dec11.gif", "dec12.gif", "dec13.gif", "dec14.gif" and so on..

 

Then I use this php script which we can call "daily.php" to match the current date (using the "Mj" date formatting system) to the image saved that corresponds to the date.  It then creates the "image3.gif" and saves it to the server.  I use CRON to automatically run this script at midnight daily.

 

Code for "daily.php"

<?php
$im = imagecreatefromgif("".date("Mj").".gif"."");
imagegif($im,"image3.gif");
?>

 

I then give out the code which references "image3.gif"

 

Image3.gif is the only image that will always change every day.

 

With this in mind, how would I implement the suggestions you guys previously mentioned so it would work not only on regular websites but social networking sites such as myspace that don't allow JavaScript, Meta tags, or Server Side Language.

 

Thanks.

Link to comment
Share on other sites

With this in mind, how would I implement the suggestions you guys previously mentioned so it would work not only on regular websites but social networking sites such as myspace that don't allow JavaScript, Meta tags, or Server Side Language.

 

that was the point I was making - you cannot implement a no-cache code on any website that does not allow Client Side or Sever Side scripting languages or Metas. you probably can use a serve side image on most sites; like the script example you have: <img src="http://www.mydomain.com/pics/myPic.php"> - but you not going to be able to produce a random query string on the end of your image (which help prevent image cache).

 

but for sites that do allow you to use your code - do something like this with your php code:

 

 

<?php
$currentday = date("z");
$im = imagecreatefromgif("".date("Mj").".gif"."");
imagegif($im,"image". $currentday .".gif");
?>

 

Link to comment
Share on other sites

 ... point the src to a php script that serves the image dynamically, still with the param for the same reason.

 

This is whtat I was refering to.  Is there anyway I could point to the php script that I have or modify it so it would work for me?

Link to comment
Share on other sites

yes - but since some social most social social networks and some websites do not allow javascript or server side scripting; you are not going to be able to use a random query string on the end of your image's src. however, most websites will allow you to embed a php image in their sites.

 

you would do it like this:

 

<img src="http://www.yourdomain.com/mypic.php">

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.