This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes How to ensure a page not cached. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to ensure a page not cached." Watch "How to ensure a page not cached." New topic
Author

How to ensure a page not cached.

Matt Brown
Ranch Hand

Joined: Jan 26, 2004
Posts: 70
I�m writing a JSP that contains sensitive data. I do not want the browsers to cache the pages. Is the following code enough to ensure that the browsers (IE, Netscape, and Firefox) would not cache the contents of the pages:

<head>
<meta http-equiv="expires" content="-1">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
</head>

I know some browser may ignore the <head> sections of HTML. Any suggections?


"I just use my muscles as a conversation piece, like someone walking a cheetah down 42nd Street." - Arnold Schwarzenegger
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61084
    
  66

See the Servlets FAQ.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Matt Brown
Ranch Hand

Joined: Jan 26, 2004
Posts: 70
Is it true that some browsers can be configured to ignore <meta> tags?
Matt Brown
Ranch Hand

Joined: Jan 26, 2004
Posts: 70
Bear & Eric,

Is it possible to clean up the cache with JavaScript?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
JavaScript has no control over the uses cache.

If you are worried about JavaScript external files or images being cached. What I do at build, all of the images/javascript/css in the application get a timestamp appended to the url

<img src="foo.gif?build=1.2.0001"/>

The querystring forces the new versions to be retrieved. Now for the html page, you need to rely on the meta tags. Caching is a good thing since it serves pags up fast for users that have multiple visits, but it can also bite you in the butt if you update alot!

If you are talking about Ajax calls see this: http://radio.javaranch.com/pascarello/2005/10/21/1129908221072.html

Eric
Mathias Nilsson
Ranch Hand

Joined: Aug 21, 2004
Posts: 367

<img src="foo.gif?build=1.2.0001"/>


Nice Haven't thought of that.


SCJP1.4
Matt Brown
Ranch Hand

Joined: Jan 26, 2004
Posts: 70
Originally posted by Eric Pascarello:
JavaScript has no control over the uses cache.



I think you can use FileSystemObject ActiveX to access local files in IE and XUL local file access API in FireFox from javascripts, but it may be dangerous to do so...
[ June 05, 2007: Message edited by: Matt Brown ]
 
Don't get me started about those stupid light bulbs.
 
subject: How to ensure a page not cached.