Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent html5 page from caching?

Tags:

html

caching

I converted a plain vanilla HTML page to HMTL5/CSS3 with a responsive layout, and for security reasons (dictated by the security people) the page must never cache.

The page previously used <meta http-equiv="Pragma" content="no-cache"> and <meta http-equiv="Expires" content="-1"> to prevent the page from being cached.

What replaces this in HTML5? How do you prevent an html page from caching in the client?

I've spent a week reading about manifest files, but they seem to do exactly opposite of what I want as attaching a manifest file explicitly causes the page it is attached to to cache.

And please don't refer me back to the w3c definition of which meta elements are now allowed — I understand that HTML5 does not include the cache-control or Pragma in meta elements.

I need to know what it does include that will prevent a page from being cached.

like image 965
gps03 Avatar asked Mar 05 '13 16:03

gps03


People also ask

How do I stop HTML from caching?

Here's how... When you're in Google Chrome, click on View, then select Developer, then Developer Tools. Alternatively, you can right click on a page in Chrome, then click Inspect. Click on the Network tab, then check the box to Disable cache.

Which http equiv prevent the browser from caching the page?

HTTP-EQUIV META tags Pragma: no-cache prevents caching only when used over a secure connection.


2 Answers

In the beginning of code you need to use this:

<!DOCTYPE html> <html manifest="manifest.appcache"> ... 

Then create manifest.appcache with such content:

 CACHE MANIFEST  # Cache manifest version 1.0  # no cache  NETWORK: * 
like image 193
n1ckolas Avatar answered Oct 03 '22 11:10

n1ckolas


I dislike appcache a tremendous amount. It almost works well but can be a real unforgiving pain. While doing some code refactoring, I realized that after logout, i could browse back to the the last page. Of course, refreshing browser it would force user back to login but this is not desired.

After searching around and seeing the options, I started to get a bit frustrated. I do not want to use appcache. I then realized that my code was redirecting to login page after destroying the session and got an idea, what if, I redirect to the home page instead? And voila, page was loaded, session checked (and of course not there), user redirected to login. Problem solved.

like image 40
Dan Doyon Avatar answered Oct 03 '22 12:10

Dan Doyon