I ran my site through Google Page Speed on Tuesday, and scored a surprising 88 out of 100–higher than I expected. Getting above 90 is going to take some optimizations on files that WordPress updates may change, so I’m hesitant to do that, but one thing it told me to do was to cache more aggressively. That’s pretty easy, as it turns out, and I could definitely feel a difference afterward.
Here’s the trick.
First, install the Apache module “expires” with this command (become root first, either using sudo or su):
Next, edit your .htaccess file in your root directory (/var/www/.htaccess in my case; yours may vary) and add these lines:
ExpiresByType image/jpg "access plus 1 week"
ExpiresByType image/jpeg "access plus 1 week"
ExpiresByType image/gif "access plus 1 week"
ExpiresByType image/png "access plus 1 week"
ExpiresByType text/css "access plus 1 weeks"
Then restart Apache with this command:
That got me another point in Google’s grading scale. But I don’t care about that as much as I care about the increased speed. I thought caching happened automatically. Evidently not. I wish I’d discovered this years ago. I even see the difference accessing the server locally over the same gigabit network.
I was able to shave 200 bytes off the PNG image that Google wanted me to optimize by using a utility called pngcrush, installable on Debian with this line:
apt-get install pngcrush
I then did this:
pngcrush -brute wordpress_icon.png wordpress_icon2.png
mv wordpress_icon.png wordpress_icon3.png
mv wordpress_icon2.png wordpress_icon.png
I diddled with the pngcrush options a bit but nothing got me anything better than a plain -brute option did. Even after doing that, Google thought I could do better, but I don’t see any point in fretting any more over what’s now a 2.1KB file.