How to force a browser to update a cached version of a web page

I have a website that, due to a poorly prepared apache conf file, instructed users to cache the website URL for several years in the future. As a result, when a person visits a site, they often do not even try to request a page. The browser just loads the HTML from the cache.

This website is about to receive a major update, and I would like users to be able to see it. Is there a way to get me to actually re-request a webpage? I am afraid that for some users, unless they press F5, they can see the old web page for several years.

+24
caching apache
Jul 30 '09 at 15:45
source share
8 answers

Use different URLs. If the main entry point to your site (for example, the main index file) is cached, then you are screwed up ... maybe you need to register another domain name?

+18
Jul 30 '09 at 15:58
source share

There are several options for achieving this. First, add a meta tag in the section:

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

Basically, the browser will not cache the page.

Another option is to establish sessions, this will force the browser to a new session each time it goes, and thus the browser will receive the page from the server, not the cache

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

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

+4
Jul 30 '09 at 16:01
source share

It can be argued that if your “main update” is in just a few (2 or 3) weeks, you only need to reconfigure your apache conf now (without further things for html - only for assets and content that will most likely never change) . By default, Firefox’s cache is ~ 50 MB, and that’s not so much, because images are also cached, and modern websites have a lot of content.

Not perfect - but that's what I would do - when I don’t want or cannot change the URL;)

+4
Jul 30 '09 at 16:36
source share

I think there is no way to do this. If they never contact your son, you really have nothing to do.

+2
Jul 30 '09 at 15:56
source share

change the urls of each resource

+1
Jul 30 '09 at 16:29
source share

I understand that this question is very old, but I have a viable answer:

Of course, you can force the new URL to avoid shared caches (not long-lived) ...

those.

  • Add request to static .js / .css / .html files
  • Add pragma meta tag for no-cache
  • Server-side redirects, no cache, cookies, sessions, etc.

However, in a scenario like this (previously edited apache.conf for long-term caching), since you cannot change the domain for SEO purposes, there is a “raw hack” that you can use, which minimizes the impact on SEO:

Copy your index page (i.e. index.php) to a new page (e.g. index_new.php) and edit httpd.conf (or the equivalent) so DirectoryIndex is a new page. Then just delete or move your old page, it theoretically should always be redirected to a new page.

those. on Debian / Ubuntu:

 cd /var/www cp index.php index_new.php sudo vim /etc/apache2/sites-enabled/000-default <Directory /var/www/> ... DirectoryIndex index_new.php </Directory> mv index.php index_old.php sudo service apache2 restart 

And there you go.

+1
Apr 22 '13 at 18:57
source share

Late, but it may help someone in the future: if you have a javascript file that is not cached in the future (i.e. if you have any way to run new js on a cached site), add some js that will programmatically clear the cache . After the configuration is fixed and / or the update is completed, clear the js cache flush.

Ctrl + F5 in jquery to clear browser cache

+1
Jan 05 '16 at 15:48
source share

You can make all the necessary changes inside HTML files, for example

 <meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, pre-check=0" /> <meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta http-equiv="pragma" content="no-cache" /> 

But also you can directly tell Apache to use the mod_expires.c module and add a couple of directives to the httpd.conf file:

 <IfModule mod_expires.c> # Turn on the module. ExpiresActive on # Set the default expiry times. ExpiresByType text/html "modification plus 5 seconds" ExpiresByType text/javascript "modification plus 5 seconds" ExpiresDefault "access plus 2 days" </IfModule> 

Thus, you add cache control of HTTP headers and end them before replies so that the browser updates the cache 5 seconds after the file was changed at the beginning, for these files, and 2 days after accessing the browser for all other types files.

Hope this helps.

0
Apr 18 '18 at 15:53
source share



All Articles