Tech Stuff

The Most Important Thing I Learned About WordPress Last Week


The Broadway Bach web site was painfully slow. Sure, it was running a bunch of plugins, but that didn’t explain all of the response problems. Running various suites of why-is-this-so-dam-slow diagnostics, I removed some things, optimized some things, compressed some things.

And while Deferred JavaScript and WP Super Cache helped some (Better WP Minify might have, but it tends to break any slideshows you might have) [updated: BWP version 1.2.3 works better], the biggest single improvement came from leveraging browser-side caching. The first page comes over better because of Super Cache, but subsequent pages go fast because of the browser-side.

It’s the difference between this:

See all those “200” server requests? All those files are being read and transmitted to you in their glorious entirely. A lot of requests, a lot of bandwidth, a lot of time. 493.3kb, to be precise.

And this:

That’s right. The 304 requests take zero bytes. Those image files, stylesheets, navigation widgets, banners and so on haven’t changed (and aren’t likely to) so the server just signs off on them, “yup, they haven’t changed, go ahead and use them.” Just 10.8kb is being transmitted.

This is what you drop into your .htaccess file to make sure it happens:

#Enable browser caching
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType image/x-icon "access 1 year"

ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 hour"

ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/javascript "access 1 month"
ExpiresByType text/javascript "access 1 month"
ExpiresByType text/x-js "access 1 month"

ExpiresByType application/x-shockwave-flash "access 1 month"

ExpiresByType video/quicktime "access 1 month"
ExpiresByType audio/mpeg "access 1 month"
ExpiresByType audio/mp3 "access 1 month"
ExpiresByType video/mp4 "access 1 month"
ExpiresByType video/mpeg "access 1 month"
ExpiresByType audio/ogg  "access 1 month"
ExpiresByType video/ogg  "access 1 month"

ExpiresDefault "access 2 days"

#Enable GZIPping
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript application/javascript
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

You’re welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *