Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to ensure a page not cached.

 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64851
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the Servlets FAQ.
 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it true that some browsers can be configured to ignore <meta> tags?
 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear & Eric,

Is it possible to clean up the cache with JavaScript?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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


Nice Haven't thought of that.
 
Matt Brown
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic