How to force a browser to refresh a cached version

2019-01-22 06:37发布

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.

8条回答
该账号已被封号
2楼-- · 2019-01-22 07:23

change URLs of every resource

查看更多
何必那么认真
3楼-- · 2019-01-22 07:27

I think that there is no way of doing this. If they never contact your sever there really is nothing you can do about it.

查看更多
The star\"
4楼-- · 2019-01-22 07:29

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?

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-22 07:29

Years late, but it might help someone down the road: if you've got any javascript file that isn't cached years into the future (i.e. if you have any way of running new js on the cached site), add some js that will programatically clear the cache. Once the configuration is fixed and/or the update complete, remove the cache clearing js.

Ctrl + F5 in jquery to clear browser cache

查看更多
放我归山
6楼-- · 2019-01-22 07:35

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

Of course you can force new URL's to avoid common caches (not long term ones)...

I.e.

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

However in a scenario like this (formerly edited apache .conf for long time caching) since you cannot change the domain for SEO purposes, there is a 'crude hack' you can use which will minimize the impact to SEO:

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

I.e. in 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.

查看更多
劫难
7楼-- · 2019-01-22 07:38

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

查看更多
登录 后发表回答