Kbase 19175: How To Get Around Web Browser Caching
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  17/03/2003 |
|
Solution ID: 19175
GOAL:
How to Get Around Web Browser Caching
CAUSE:
A common problem experienced with WebSpeed is that pages do not appear to be refreshed. When making requests to a WebSpeed application, the same page is being returned, even though the information has been changed. This is not a WebSpeed issue, this is a problem with the web browser.
When a browser makes a GET request to a web server, many popular browsers keep a copy of the returned page in a cache. The idea behind this is that if the details of the page have not changed, the page is reloaded from cache, rather than re-processed by the web server, which relieves load on the web server, and makes for a faster perceived response on the web browser. This does not affect a POST request. POST requests are not cached.
Typically, you will see this if you make a GET request for the same URL multiple times from the one browser session. The web browser and/or web server will determine that the contents of the requested page have not changed, and so the browser will retrieve the page from its cache. Depending on the browser, you can force it to reload from the web server (rather than from cache) if you suspect that pages have not been reloaded. However, some users may not realize this has
happened.
FIX:
There are several ways to get around this caching:
1. Turn off the caching on your browser. This will depend on the browser you are using, but there is usually some option where you can indicate when to cache pages or not. However, on a WWW server, there is no guarantee that all users will have this set. This means that they will think your website is not working correctly. This requires one of the other methods to get around.
2. Make your URL unique every time. If the URL is different, the browser will not have a copy in the cache, and therefore will force the whole page to be reloaded. One suggestion to implement this would be to add a variable to the end of the URL with the current time on it. For example:
{&OUT} '<A HREF="' url-encode('webobj.p?',?)
url-field("time",string(time),?)
'">Go to this link '.
This will generate a different URL each time, as the time has been appended to the QUERY_STRING, and the browser will not reload the same page from cache.
3. Set up HTTP headers to indicate that a page is not to be cached. This is done by setting the following HTTP headers:
Cache-Control: No-Cache
Expires: 0
This can be done within WebSpeed as follows (typically, in the output-headers procedure), before you output the content type (that is, output-content-type):
output-http-header("Cache-Control","No-Cache").
output-http-header("Expires","0").
4. Another way of doing 3) above is to use <META> tags within the head section of the HTML page. The tags you would require are:
<meta http-equiv="Cache-Control" content="No-Cache">
<meta http-equiv="Pragma" content="No-Cache">
<meta http-equiv="Expires" content="0">
To output this with WebSpeed, use:
{&OUT}
'<meta http-equiv="Cache-Control" content="No-Cache">' skip
'<meta http-equiv="Pragma" content="No-Cache">' skip
'<meta http-equiv="Expires" content="0">' skip.
This does cause problems when using the "Back" button on the browser, or when resizing the page.
FIX:
References to Written Documentation:
http://www.w3c.org
- HTTP Specification (Cache-Content and Expires headers)
- HTML Specification (<META> tag)