Technical Discussion
  >> Web Design / HTML / Web hosting Forum


Register (or login) on our website and you will not see this ad.


  Print Thread
Standard User longedge
(member) Wed 22-Aug-12 16:17:51
Print Post

Preventing page caching.


[link to this post]
 
I run a small web site for our local Social Centre. The index page contains a jpeg of the poster for the next event and nothing else. To update the page I just upload the latest image as necessary. Clicking the image takes you into the site. It all works very well except that I can't stop the image on the index page being cached (on my machine at least). Returning to the page displays the last image loaded unless I actually force a re-load.

I've just added a further line to the head section to force a refresh once every 30secs but I wonder if I've missed something obvious that would allow me to take that line out again as it feels wrong somehow to be doing this. The three relevant lines are currently:-

<META http-equiv="refresh" content="30">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache" />
<META HTTP-EQUIV="Expires" CONTENT="-1" />


Any ideas please?
Standard User cheshire_man
(knowledge is power) Wed 22-Aug-12 17:24:18
Print Post

Re: Preventing page caching.


[re: longedge] [link to this post]
 
Is this helpful?

Tony
Standard User camieabz
(sensei) Wed 22-Aug-12 17:29:21
Print Post

Re: Preventing page caching.


[re: longedge] [link to this post]
 
Do you use a .htaccess file?

Assuming your images are .gif and .jpg, I would have this specific image as a png, and use the code in the .htaccess:

<FilesMatch ".(png)$">
Header set Cache-Control "max-age=1"
</FilesMatch>


The age value of '1' will mean the image will expire after 1 second. You might want to set it to something more realistic, such as 3600 (1 hour). If you were to use the same file format for all the images, all images would not get cached (increasing site load times and bandwidth).

~ Camieabz ~

All Connection Data ~ Some plusnet links

mod'er·a'tion n.
Synonyms: temperance, restraint, modesty.


Register (or login) on our website and you will not see this ad.

Standard User longedge
(member) Wed 22-Aug-12 19:29:47
Print Post

Re: Preventing page caching.


[re: cheshire_man] [link to this post]
 
The markup that I'm using is pretty much as mentioned in the link. I just realised that for some reason I've got a closing slash on each line, don't know where they came from. I don't know whether that would cause a problem? I've taken them out anyway.

I don't use .htaccess except to control access to one sub-directory. I use jpegs across the site so if all else fails I'll make the poster a .png and try that.

Edited by longedge (Wed 22-Aug-12 19:37:38)

Standard User longedge
(member) Wed 22-Aug-12 20:15:52
Print Post

Re: Preventing page caching.


[re: longedge] [link to this post]
 
It seems as if the stray slashes were to blame. I've just made slight changes to the image a couple of times and then gone to the index page after uploading a new version. It now seems to work as it should. Thanks for the suggestions.

Edited by longedge (Wed 22-Aug-12 20:16:51)

  Print Thread

Jump to