Solved

How to bust website's cache serverside? It's showing the old version.

Posted on 2014-01-09
11
220 Views
Last Modified: 2014-10-22
Hello,

I have a wodpress site that I recently migrated from a dedicated server to cloud servers. It was still showing me the old version (new content wasn't appearing) on my computer so I cleared cache and that fixed it.

On my phone it still shows the old version that doesn't have the latest content. A few friends have also told me they see the old version, so I am guessing a lot of my old visitors see the same thing.

How can I solve this? I tried putting this in the header.php of the site on the old and new server:

<meta Http-Equiv="Cache-Control" Content="no-cache">
<meta Http-Equiv="Pragma" Content="no-cache">
<meta Http-Equiv="Expires" Content="0">

Open in new window


But it hasn't helped.

DNS records properly point to the new site.

How do I fix this cache issue?

Thank you!
0
Comment
Question by:it1000
  • 4
  • 4
11 Comments
 
LVL 12

Expert Comment

by:aindelicato
Comment Utility
do you have any cache plugins installed like Super Cache?

See this site:
http://wp.tutsplus.com/tutorials/scaling-caching/wordpress-caching-plugins/



Disabling Browser Cache in HTML
With this code placed in the top of the head section you can turn off client side caching.
1
2
3
4
5
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<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" />

Disabling Server Side Cache in PHP
This little two liner code goes to the uppermost part of a PHP file.
1
2
3
4
<?php
    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Those are good suggestions and i use them myself.  The trouble with all of those methods is that they don't take effect until the current cached items expire.  The server can not clear the browser cache.  It can only 'ask' that the page not be cached when it is finally loaded from the server.  

Note that the purpose of caching is to speed up web browsing.  If you set it up so that nothing is cached, you force the browser to go back to the server for everything which is slower.  In addition, preventing caching of the HTML does not stop caching of images and javascript.  I frequently change the name of the images or javascript in a new version of a page so that the page will fetch the new versions of images and javascript too.
0
 

Author Comment

by:it1000
Comment Utility
Thank you for your replies. I just want to get over this hurdle then I will set things back to normal.

I tried putting that code in the headers of both the old and the new site, didn't help.

Also, this may give you a clue:

I logged into the old site, deleted the latest articles, and refreshed the site on my phone. If it was indeed pulling from the old site, then the latest articles should disappear since I deleted them. But they still do appear.

How can I basically make the site convince my phone's browser to refresh the content?

I also thought it might be DNS related so I check the domain ttl but it's 1 hour, so it can't be. I migrated the site days ago.

Thank you for your help with this pesky issue.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
The cache that is giving you a problem is in your browser on your computer and phones.  Nothing you do on the server will have any effect until you are able to load a new page from the server and not from your cache.  This is a problem I run into all the time when I upload a new pages for a website.

You have to look up the method for forcing your browser to do a complete refresh from the server.  In IE and Firefox on the desktop, it would be Ctrl-F5.  I don't know what it would be on your phone.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:it1000
Comment Utility
I did CTRL-F5 and it didn't help.

Also, I deleted everything in /wp-content/cache

Even if CTRL-F5 worked, I cannot ask all my visitors to do CTRL-F5

The only thing that has worked so far is clearing my cache in Chrome. Sure, it solves the problem for me, but the real problem is my visitors.

There has to be a way, no?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
No, no way.  The server can Not clear what is in the client's cache.  All it can do is ask it not to cache the page... when it finally gets a new copy.  

Even more to the point, the server can not do Anything to the client except respond to requests.  And the browser on the client will only ask for a new copy of the page when the cached copy expires or you tell it too.
0
 

Author Comment

by:it1000
Comment Utility
Good point, I've been digging around and I think that making the browser believe all files have been recently modified will make it request new versions, which would effectively solve the problem.

How can I force Last-Modified in htaccess? Basically I want every request to tell the browser that the file in question has been modified today!

Any other ways? Can I change the last modified date for all files for my site, alternatively? If so how?

I think this should solve the problem.
0
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
Technically, the browser makes a 'conditional' GET request with "If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field."  http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html  The server response if the server sees no change in the file date is a "304 Not Modified".

Here is the RFC on caching: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13

Thru FTP or a script on the server you can change the date of the files.  While in theory that should work, I know from experience that it doesn't always work.  This is especially true of files that are loaded from the HTML file like images and javascript.  I have at times had to load an image or javascript directly in the browser and then do a Ctl-F5 refresh to get it to update.

This http://www.paulund.co.uk/set-expire-headers-in-htaccess appears to be a decent article on setting expiration times in '.htaccess'.

Still... I don't know of anything that will override what is already in your cache.  Everything I know of applies to the Next time you load the file.
0
 

Author Comment

by:it1000
Comment Utility
I tried touching all the files. Didn't help.

Anyone have any ideas?
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

#Citrix #Internet Explorer #Enterprise Mode #IE 11 #IE 8
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
The viewer will learn how to dynamically set the form action using jQuery.
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now