FREE THOUGHT · FREE SOFTWARE · FREE WORLD

Hacking WP Super Cache for Speed

So I couldn't help it, I downloaded and installed WP Super Cache because it sounded like an ideal setup for me.. A plugin built to generate static files from php+mysql for Apache to serve the way its supposed to be.. My dream.

So I started digging into the code. Its a form of WP Cache-2, but fork is a generous word at this point. There is some future add-on capability, but the code that actually performs the caching is pretty much the same. Bloated, inefficient, and redundant coding. This plugin could do the same thing with 1 file, no config, no meta, serializing, etc.. But its still a lot better than anything I've created.

AskApache Crazy Cache - coming soon

I'm very interested in this technology and this is the closest to my ideal that a WordPress plugin has come so far, I might just start from scratch one of these days, once I figure out a few php bits I'm still learning about. If I do decide to make a caching plugin the right way, it will have similar tricks that I used in the Hack WP-Cache for maximum speed post.

My WP Super Cache .htaccess

The .htaccess generated by WP Super Cache is wack, I'm not even sure how its been working for everyone, I've hacked it up a bit and this is working great for me.. Will definately be updated as I do more debugging.

I used some of the same techniques found here, and here, and these SetEnvIf examples.

# BEGIN WordPress

SetEnv HTTP_IF_GZ_MATCH .html
SetEnvIfNoCase ^Accept-Encoding$ "(.*gzip.*)" HTTP_IF_GZ_MATCH=.html.gz

RewriteCond %{ENV:REDIRECT_STATUS} !=200
RewriteCond %{QUERY_STRING} !s
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.+) HTTP/ [NC]
RewriteCond %{HTTP_COOKIE} !^.*(comment_author_|wordpress|wp-postpass_).*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/%1/index%{ENV:HTTP_IF_GZ_MATCH} -f
RewriteRule ^(.*)$ /wp-content/cache/supercache/$1/index%{ENV:HTTP_IF_GZ_MATCH} [L,NC]

# END WordPress

WP Super Cache .htaccess

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !.*s=.*
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
RewriteCond %{HTTP_COOKIE} !^.*wordpress.*$
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html.gz [L]

RewriteCond %{QUERY_STRING} !.*s=.*
RewriteCond %{HTTP_COOKIE} !^.*comment_author_.*$
RewriteCond %{HTTP_COOKIE} !^.*wordpress.*$
RewriteCond %{HTTP_COOKIE} !^.*wp-postpass_.*$
RewriteCond %{DOCUMENT_ROOT}/wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html -f
RewriteRule ^(.*) /wp-content/cache/supercache/%{HTTP_HOST}/$1/index.html [L]

# END WordPress

It's definately a complex kind of plugin in that there is a lot of directions and a lot going on, so I'm not saying anything bad about the developers, just hope to see some updates over the next few months so I don't have to mess with it.

Optimization

 

 

Comments