Jump to content

Fresh Page On Every View


Graeme

Recommended Posts

Hello All,

 

I have been adding the new fixtures to a cricket web site for the forthcoming matches this season and someone e-mailed me to say that they could only see last year's fixtures although I knew I had uploaded them.  I'm guessing it might be a caching problem.  I once read about a meta tag that can be used to view fresh content on every page load but one of our friends on here suggested not to use it if you have graphics on a page.

 

The pages in question do not have graphics so is there one I could use?

 

Thank you as always,

 

Best wishes

Graeme

Link to comment
Share on other sites

Hi,

 

We live in the age of web video, HD Youtube video and Netflix ... I am not so certain that forcing image downloads is really much of an issue. I would use php to force no cache as well:

<?php
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
header("Expires: Sat, 27 Jul 2001 06:00:00 GMT"); // Date in the past
?>

Or:

header("Location: yoursite/index.php?r=".mt_rand(0, 9999999));

Stef

Link to comment
Share on other sites

Hi,

 

Yep ... header information has to be at the very top of the page, otherwise you will get an error. 

 

Why?

 

You can't send header information after you've sent body information:

 

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

 

 

Check it out:

 

http://www.php.net/manual/en/function.header.php

 

Stef

Link to comment
Share on other sites

Hmm .... cache control is always a dice-roll from my experience, to a certain extent. I think doing it via PHP (server side) would be better because it forces the fresh load of the page. 

 

That said, I would be using this PHP:

header("Location: yoursite/index.php?r=".mt_rand(0, 9999999));

.... This basically tricks the browser into thinking this is a new page, so it does not load from cache. 

 

But then again, try all of it and see what happens. 

 

 

Stef

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...