5

We are experiencing an issue where a previous version of our home page is being displayed. Even though there has been changes since then, the web page will always show the old version.

This issue stems from us using a WordPress plugin that added a Last-Modified: Tue, 19 Apr 2016 15:18:40 GMT header to the response.

The only way found to fix this issue is by force refresh on the browser. Is there a way to invalidate that cache remotely for all clients ?

The Request-Response header

Louay Cheikh
  • 53
  • 1
  • 1
  • 5

3 Answers3

11

If you mean the stylesheets or javascript for example you can update the version of the stylesheet see below for an example

<link rel="stylesheet" type="text/css" href="mystyle.css">

You can change to

<link rel="stylesheet" type="text/css" href="mystyle.css?v=1.0">

Notice the ?v=1.0 parameter at the end of the source, this works for Javascript also.

If you need images and things to update you can find lots here about cache busting here

Refresh image with a new one at the same url

you can also try adding

<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="Mon, 20 Feb 2012 00:00:01 GMT">

To the Head of the HTML Page.

GeordieShorn
  • 136
  • 1
  • 4
  • The issue is not about cache busting the CSS or JS files. The issue is the actual HTML page is cached. – Louay Cheikh Feb 22 '18 at 14:36
  • Are you using a CDN such as cloudflare? – GeordieShorn Feb 22 '18 at 14:38
  • Nope, we are using varnish on an AWS instance. – Louay Cheikh Feb 22 '18 at 14:50
  • 1
    So is the actual HTML page is being cached, right ?? Since I don't really have a lot to go off you could try what I added to the original answer – GeordieShorn Feb 22 '18 at 15:02
  • 1
    Even if I do add the above meta tags it won't matter because clients will not get the updated HTML they will see the cached one. So i dont think it will solve our problem. – Louay Cheikh Feb 22 '18 at 15:15
  • Thats a good point, can you give us a little more information, is this just plain HTML or any PHP. CMS or literally just a plain HTML File, are you able to change the name of the file or link for example: home.html > home_new.html. To force refresh of the html page? – GeordieShorn Feb 22 '18 at 15:34
2

Browsers are going to honor the cache settings that were originally provided to it, you should be able to look in the developer tools of the browser to see what the cached headers are.

For example, if the content sent something like:

Cache-Control: public, max-age=86400

Then it will have no reason to request an updated version of the content from your server for a day.

If the server is able to handle the load of receiving requests for the content, you can do ensure that there is an ETag and Last-Modified header, and then use a short expiration time, such as:

Cache-Control: public, max-age=600
ETag: abcdefg
Last-Modified: Tue, 19 Apr 2016 15:18:40 GMT

Then, after 10 minutes the browser will issue a request that asks the server if the content has changed. If not, the server should issue an empty 304 Not Modified response to indicate no difference. So this saves on your bandwidth and the only cost is however "expensive" resource-wise it is to determine the headers to send.

I would absolutely suggest using small cache times for your primary HTML (or any dynamic content) if you know it will change as the entire purpose of those caching headers is to allow browsers to serve as quickly as possible the version they have as well as save you on CPU and bandwidth.

Side note: If you were able to "reach out" to it in that way, it would actually be somewhat terrifying.

Joshua DeWald
  • 2,729
  • 18
  • 16
1

Based on all of the information provided, you're missing on Varnish HTTP Purge plugin and/or have not configured the VCL for it.

If you're seeing old cache version for the homepage this means that the page's cache was not purged after updating its contents in Wordpress admin.

In a typical scenario for Wordpress, you will set maximum cache lifetime and use a plugin like the one mentioned to invalidate cache based on relevant Wordpress hooks.

Danila Vershinin
  • 6,133
  • 2
  • 20
  • 25