PDA

View Full Version : If page content is New, Refresh Page



simonf
03-08-2006, 07:27 AM
Hi Guys

I'm looking for a script that looks at the page(s) content and is not the same as in the cache etc, refreshes the page on load.

Any suggestions...

jscheuer1
03-08-2006, 03:57 PM
In javascript, not that I know of. Other than this battery of meta tags (may be others, these not 100% effective in all browsers, I am told):


<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="Mon, 01 Jan 1990 12:00:00 GMT">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache-control" content="must-revalidate">
<meta http-equiv="Cache-control" content="max-age=0">

I'm not, as I say, aware of anything in javascript however, due to some experiences as webmaster on various servers over the years, it appears to me that there must be something server side that can affect this to a degree, with individual browsers having some say in the matter.

Neither of these two avenues refreshes the page per se rather, they detect if there is new content and have the browser serve from the source instead of the cache or always serve from the source - if that is allowed by the browser's settings/default behavior.

simonf
03-09-2006, 08:33 AM
Thanks John.. as always.....

mwinter
03-09-2006, 08:38 PM
In javascript, not that I know of.There isn't any way.


Other than this battery of meta tags (may be others, these not 100% effective in all browsers, I am told):User agents aren't required to respect meta elements at all, and intervening caches, which can be just as important as the browser (if not more), will never check them. HTTP headers should always be sent by the server.



<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="Mon, 01 Jan 1990 12:00:00 GMT">
<meta http-equiv="Cache-control" content="no-cache">
<meta http-equiv="Cache-control" content="must-revalidate">
<meta http-equiv="Cache-control" content="max-age=0">I have issue with the first and third elements (or their proper HTTP equivalents). Attempting to prevent any sort of caching is rarely productive, and only forces the client to make requests that it may not need to do. Trying to prevent caching is appropriate if the resource always changes, or in an effort to protect privacy, but should be avoided at other times. Caching is your friend. :D

What is important in this situation is revalidation. This will automatically occur whenever the cache finds the resource to be stale. Properly chosen Expires header and max-age Cache-Control directive values will accomplish this just fine.


[...] with individual browsers having some say in the matter.As always, the user has the final say. If they configure their browser to only revalidate periodically, rather than whenever indicated by the server, there's little that can be done.

One approach is to make the URL unique, usually by adding a timestamp to the query string. As the majority of the URL (all of it except the fragment, if present) identifies a resource, even changing the query string will make the browser consider it to be different, forcing an end-to-end request.

Mike

jscheuer1
03-09-2006, 11:07 PM
Originally Posted by jscheuer1
In javascript, not that I know of.

There isn't any way.


One approach is to make the URL unique, usually by adding a timestamp to the query string. As the majority of the URL (all of it except the fragment, if present) identifies a resource, even changing the query string will make the browser consider it to be different, forcing an end-to-end request.

A circular post in that the query string could be appended via javascript. I know this would be a javascript enabled only solution but, perhaps that is all simonf requires.

mwinter
03-09-2006, 11:30 PM
A circular post in that the query string could be appended via javascript.I never said that scripting couldn't be used as part of a solution to the general problem of retrieving fresh versions of a resource, just that it couldn't be used to do what Simon asked: to compare cached and origin content, and force an update if the former is out-of-date. :)


I know this would be a javascript enabled only solution but, perhaps that is all simonf requires.Perhaps, but sending accurate HTTP headers is still a good idea.

Mike