Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force a browser to refresh a cached version of a webpage

Tags:

caching

apache

I have a website that because of an ill-prepared apache conf file has instructed users to cache a website URL several years into the future. As a result, when a person visits the site, they often make no attempt to even request the page. The browser just loads the HTML from cache.

This website is about to get a major update, and I would like for users to be able to see it. Is there a way for me to force a user to actually re-request the webpage? I fear that for some users, unless they happen to press F5, they may see the old webpage for several years.

like image 624
Chris Avatar asked Jul 30 '09 15:07

Chris


People also ask

How do I force Chrome to reload a page?

Google Chrome Or hold down Ctrl (Control) and click the Reload button. Or hold down Ctrl (Control) and click F5. Or Open Chrome dev tools by clicking F12 and right-click Reload button. Then, click Hard Reload.

How do I manually refresh a page?

Ctrl + F5 is the shortcut to trigger a refresh, which will force the page to reload. To make the browser refresh without relying on the cache, use Shift + Ctrl + F5. This triggers a “hard refresh”, so the browser pulls up the newest version of a web page.


2 Answers

There are several options to achieve this First In the section add meta tag:

<meta http-equiv="pragma" content="no-cache" /> 

Basically the browser won't cache the page.

Another option is to set sessions, this will force the browser to a new session each time they go, and thus make the browser get the page from the server instead of the cache

<?php session_start();  $_SESSION = array(); session_destroy();  ?>  

You can add this to your website for a couple of days and then remove. I really don't know if it will do, but perhaps you will find it useful

like image 25
Sorantis Avatar answered Oct 18 '22 09:10

Sorantis


Use different URLs. If the main entry point to your website (like the main index file) is cached, then you're screwed... maybe you should register another domain name?

like image 160
liori Avatar answered Oct 18 '22 09:10

liori