4

We've just launched a new website. This was a complete redesign, including a change from a static HTML website, hosted on Server A, to a WordPress site hosted on Server B. (the relevance of that is server caching)

I've sent the new website to members of our team, some of whom haven't been on their computers since 20-Dec-2021 (its now 11-Jan-2022) and their computer has displayed the old website to them. The HTML of the old website gets served to them, but not the images. So in essence they get a broken site. They can get the new site by refreshing the page.

This is obviously some sort of caching issue, either browser or server, I'm not concerned about our team members, but am concerned about potential customers who have previously visited the site getting served the wrong and / or broken site.

The homepage URL is still the same (eg. https://example.com) so I can`t force them to see the new site that way.

Any ideas how I can force users who have previously visited the old site to see the new site?

Further info: I'm running a LAMP stack with Plesk.

3
  • 3
    You could try throwing a bogus query string in the url to bust the cache. Like example.com?newsite Jan 11 at 17:57
  • Thanks @StephenCollins , so that i can test that myself is there a way to see if a page im served is new or from the cache, baring in mind i already have the new site saved in my computers cache.
    – sam
    Jan 12 at 14:00
  • @sam you can look in the server log file to see what if anything, eas requested. Cached pages wont be requested from the server!
    – davidgo
    Jan 13 at 17:16

3 Answers 3

4

You are likely out of luck. There is nothing you can do to uncache a client other then wait out the caching period.

Delending on how bad the caching is, you may get some relief by using a different subdirectory, or, as @Stephencollins commented adding irrelevant parameters to the URL.

Alternatively you could launch the new site on a different domain.

I'd suggest the first step is to try ascertain how long the caching is /was being set for.

2
  • 1
    Thanks unfortunately changing the subdirector / domain would negatively effect the SEO so is a non starter for this site. How can i tell how long the browser cache is for ? Ive checked the htacess and there is nothing set for the html / css / js cache headers as far as i can tell
    – sam
    Jan 12 at 14:02
  • It sounds like the cache time may be based on the last-modified date of the page. Browsers cache the page for 1/10th of the time between when the page was last modified and the current date, or until the browser is restarted. Jan 14 at 9:30
2

So that users don't see broken pages, you should make sure that your old images, css, js, etc get copied to your new server. That way, even if a user is viewing an old copy of the page, the browser can still fetch any resources it needs to render that old page and prevent it from looking bad, even if it isn't up to date.


If there is a JavaScript file that is loaded by the old site, you can use it to force users to get the new site. You can replace its contents on the new server with code that forces the page to reload.

window.location.reload();

The new site shouldn't have a reference to this JS to prevent the site from continually refreshing.


You should set proper cache control headers so that you don't have this problem again in the future. Rather than making browsers guess how long they can cache pages, you should explicitly tell them.

For a site based on Apache, you can put something like this in your .htaccess file:

# Default caching: 1 day
Header set Cache-Control "max-age=84600, public"

# Resource caching: 1 week
<FilesMatch "\.(ico|jpg|jpeg|png|gif|svg|webp|pdf|js|css)$">
  Header set Cache-Control "max-age=592200, public"
</FilesMatch>

That would mean that everybody gets new HTML within 24 hours and changes to images and scripts with in a week. I usually recommend longer cache times for resources because changes to them can be forced by using version parameters on their URLs.

-1

Might be silly of me to ask but have CTRL+F5 keys been used?

I ask because my goto browser is FireFox and clicking Refresh doesn't always reflect changes made to my dev or production sites unless, those two keys a pressed. Sometimes it takes up to three goes of that key combo for the change to display especially images and favicons.

UPDATED: OK understood sam, maybe use a JS Alert on the site to advise users to force a refresh?

Or using the htaccess file to redirect as in: Redirect 301 / https://example.com or Redirect /path/to/old/file/old.html /path/to/new/file/new.html maybe even this, RedirectMatch 301 ^/blog/about /blog/about.html. There's a few examples out there that should suit.

Using Mod rewite also come to mind.

Another thought, using Forcing a Page to Load from the Server as answered at Stack Overflow.

2
  • 2
    hard refresh (CTRL+F5) will solve the caching issue, but the problem is the users wont know to do that.
    – sam
    Jan 13 at 12:00
  • OK, maybe use the htaccess file to redirect.
    – kwaka
    Jan 16 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.