1

When viewing the home page of my site (zilredloh.com), sometimes I do not see the latest posts. A new post will have been published, but the main index page doesn't reflect this. Refreshing the browser via F5 will then show the new content.

I know that browsers will sometimes cache content, but I have not encountered such a significant caching problem before for other sites. This issue seems to happen sporadically, and I've seen it occur while using different browsers and from different locations.

This morning, I opened up the site in Safari. The most recent post displayed was dated February 10. However, there were two posts made after this time - and they don't show up at all:

Screenshot of Safari, Dev Tools

I know that if I refresh, or if I clear my browser cache - I will see the most recent content. That's not my issue. What I want to understand is where this caching is coming from in the first place.

In the screenshot above, I see a 200 Status for most assets requested. Some assets though (like Google Fonts, Google Analytics, and wp.pixel.com) are not cached.

Is this entirely due to the browser's cache? It seems unusually aggressive if so. I've reached out to my host (WebHostingBuzz), but they are telling me "There is no caching in cPanel by default."

  • I have seen this sporadic issue in Chrome, Firefox, and Safari (Mac).
  • I am using a Child Theme, based off of a custom theme.
  • I have some plugins installed, but no cache-related plugins installed.

I've made direct changes to my child theme's style.css file on the server, and after a refresh - those changes appear instantly and successfully.

Refreshing always seems to retrieve the latest and most recent files/posts, but on occasion when returning to the site... I seem to be getting a cached view. And I'm unclear why.

I would appreciate any suggestions or advice on where to focus my troubleshooting.

Thanks, -Felix


Traceroute results: Local vs. ping.eu

  • Are you using anything like cloudflare or another CDN? – JpaytonWPD Feb 19 '17 at 23:58
  • For this particular site in question (zilredloh.com), no. However, I have another WP site using the same host that does use Cloudflare. I've noticed a similar issue on that site, but only maybe once or twice. Nothing near as aggressive or frequent as on the zilredloh.com site I talk about in my example above. – avoision Feb 20 '17 at 0:17
  • When you say "Nothing is cached," are you basing that off the screenshot? Plugins installed are: Akismet, Contact Form 7, Customized Recent Comments, Faster Image Insert, Google XML Sitemaps, Incredibbble, Jetpack, PHP Code Widget, Polldaddy Polls & Ratings, WP-ConactForm, Yoast SEO. I tried looking through things, to see if something might be caching. Didn't find anything. Will try the traceroute in a few. Thanks for the suggestions! – avoision Feb 20 '17 at 1:00
  • I just also noticed in your screenshot safari is saying the (index) is cached, Now that I have talked you in circles it seems like the browser cache could be to blame, although I am not seeing it happen here. – JpaytonWPD Feb 20 '17 at 1:25
  • I posted the Safari example given how aggressive the caching seemed to be. Would normal browser caching go so far as to "ignore" new posts made? FWIW I use Chrome normally for debugging, always had cache disabled in Chrome, and would still see this issue sporadically. – avoision Feb 20 '17 at 1:29
1

You may need to set nocache headers in your main template header. Include this near the top of the header.php after the opening tag: nocache_headers()

From here: Function Reference/nocache headers

Run some tests, I believe this should only affect the main page file, other files should still cache normally.

More idealy, wordpress should be sending a last modified header with the home page. Hold on while I dig further into this.

Notice the cache-control max-age. As you can see, the cache has been set at 30 days. Meaning the browser will assume nothing has changed for 30 days unless the server sends a different header.

HTTP/1.1 200 OK
X-Powered-By: PHP/5.4.45
Cache-Control: public, max-age=2592000
Expires: Wed, 22 Mar 2017 01:15:09 GMT
Content-Type: text/html; charset=UTF-8
Link: <http://zilredloh.com/wp-json/>; rel="https://api.w.org/"
Link: <http://wp.me/1ZLfW>; rel=shortlink
Vary: Accept-Encoding
Date: Mon, 20 Feb 2017 01:15:09 GMT
Accept-Ranges: bytes
Server: LiteSpeed
Connection: close
Content-Length: 85258

After adding the code:

Notice the second set of Cache Control and Expires.

HTTP/1.1 200 OK
X-Powered-By: PHP/5.4.45
Cache-Control: public, max-age=2592000
Expires: Wed, 22 Mar 2017 02:01:16 GMT
Content-Type: text/html; charset=UTF-8
Link: <http://zilredloh.com/wp-json/>; rel="https://api.w.org/"
Link: <http://wp.me/1ZLfW>; rel=shortlink
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Vary: Accept-Encoding
Date: Mon, 20 Feb 2017 02:01:16 GMT
Accept-Ranges: bytes
Server: LiteSpeed
Connection: close
Content-Length: 85258
  • Can I assume you have added that code, I now see a second cache control with a max age of 0. – JpaytonWPD Feb 20 '17 at 2:03
  • Yes, I've added the code. I'll test in the coming days and see how this works out. Thanks so much for this suggestion. – avoision Feb 20 '17 at 2:32
  • Confirmed that this resolved my issue. – avoision Feb 28 '17 at 15:52
  • Excellent! I am gald it worked for you – JpaytonWPD Mar 1 '17 at 18:56
0

To narrow it down, perhaps try disabling cache in your browser. In Chrome - [Developer tools] > [Network] and tick the box that says "Disable cache".

  • Thanks, Matt. Already have that checked in Chrome and I've disabled cache in Chrome since forever. Which makes this issue all the more puzzling to me. – avoision Feb 19 '17 at 22:16

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.