Fixing WP Super Cache’s HTTP Expires headers

By Richard X. Thripp at 2008-11-23T03:34:12Z in News, with these tags: accounts, blogs, bugs, caching, http, problems, speed, jump to comment form. 352 words.

A while ago, I noticed that loading up my blog in Internet Explorer, the posts were out of date. I had to hit F5 to see the new material. I never had this problem in Firefox, so I didn’t know the issue.

Another thing I’ve noticed is that I have to press F5 after logging into my Thripp.com account in either browser, else I’ll get the same page with no admin bar or anything.

I figured it out today. Months ago when I installed WP Super Cache, I couldn’t get it to put the .htaccess file in /wp-content/cache/. I just guessed at it and made a file that says this:

AddEncoding gzip .gz
AddType text/html .gz

It turns out, WordPress ordinary generates HTTP expires headers and such for each pageload, but with the full HTML caching, you have to rely on Apache to do that, so the .htaccess file is essential. It should look like this:

# BEGIN supercache
<IfModule mod_mime.c>
AddEncoding gzip .gz
AddType text/html .gz
</IfModule>
<IfModule mod_deflate.c>
SetEnvIfNoCase Request_URI \.gz$ no-gzip
</IfModule>
<IfModule mod_headers.c>
Header set Cache-Control ‘max-age=300, must-revalidate’
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html A300
</IfModule>

# END supercache

I had to set up a new WordPress installation to get that, because I can’t get WP Super Cache to create the .htaccess file on this WordPress MU installation for some reason.

However, I still had the problem with getting the same page upon logging in. I examined WordPress and WP Super Cache’s HTTP headers with web-sniffer.net, and made additions to .htaccess to imitate them, so that in fact, your browser won’t cache pages at all:

# BEGIN supercache
<IfModule mod_mime.c>
AddEncoding gzip .gz
AddType text/html .gz
</IfModule>
<IfModule mod_deflate.c>
SetEnvIfNoCase Request_URI \.gz$ no-gzip
</IfModule>
<IfModule mod_headers.c>
Header set Expires ‘Thu, 19 Nov 1981 08:52:00 GMT’
Header set Cache-Control ‘no-store, no-cache, must-revalidate, post-check=0, pre-check=0′
Header set Pragma ‘no-cache’
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html A300
</IfModule>

# END supercache

I suppose that might be too harsh, as nothing is cached now. However, everything’s gzipped already if you’re logged out, so it will still be fast. I don’t want to deal with this problem anymore, and I’m glad I’ve solved it. If you use Internet Explorer, clear your cache! Firefox is smart enough to check the Last Modified date anyway (which was always correct on Thripp.com), but IE is not.

Post to Twitter Post to Plurk Post to Delicious Post to Digg Post to Facebook Post to MySpace Post to Ping.fm Post to StumbleUpon



5 Comments, newest threads first. Join the discussion. RSS feed for this entry.


Have no fear — commenting is here. Comments RSS feed.

These HTML tags work: a href, abbr, acronym, b, blockquote, code, em, i, strike, strong, u. You will be emailed if anyone replies to your comment. Gravatars work here. Thanks for commenting!