Reducing page load time by 75% with pngcrush and Apache caching

Run a test using webpagetest:
http://www.webpagetest.org/

Screen Shot 2013-05-01 at 10.17.40 PM

Found this link on different options to pngcrush:
http://www.webupd8.org/2009/11/compress-png-files-with-pngcrush.html

The best option turns out to be one of the comments. I got about 50% reduction in file sizes, which took 2/3 of the page load time off:

First, make a backup of the wp-content/uploads directory. Then in uploads do this:

for file in `find . -name "*.png"`;do \
echo $file; \
pngcrush -rem allb -brute "$file" tmp_img_file.png; \
mv -f tmp_img_file.png $file; \
done;

To add caching to Apache:

sudo a2endmod disk_cache
mkdir cache
chmod u+w cache
chown apache-user:apacheuser cache

Add the settings from here to apache2.conf:
http://www.philchen.com/2009/02/09/some-tuning-tips-for-apache-mod_cache-mod_disk_cache

<pre>

CacheRoot /somewhere/cache
CacheDefaultExpire 3600
CacheEnable disk /
CacheDirLevels 2
CacheDirLength 1
CacheMaxFileSize 1000000
CacheMinFileSize 1
CacheLastModifiedFactor 0.1
CacheMaxExpire 86400
CacheStoreNoStore On
CacheStorePrivate On

</pre>

Note he has some settings duplicated. I also feel that the default cache timeouts may be low for a blog – an hour versus a day or week. I removed some of his settings, as they ignored URL parameters which identified specific posts, leaving all posts to render the same way.

Overall this has a similar effect to installing Varnish as a cache – this is simple on VPS though, and took no effort to set up. My past efforts to set up nginx/WP-Super-Cache etc have all ended in frustration. The last step of Apache caching has remove about another 30-40% off the page load time.

To make WordPress work, “RewriteRule . index.php [L]” into “RewriteRule ^(.*)$ index.php/$1 [L]“. This ensures URL parameters are passed through, without which a lot of things cache as the same thing, when they shouldn’t.

You should also add this to the Apache configuration – this prevents sending gzipped content to clients that don’t support it.

Header append Vary: Accept-Encoding

Here’s the final result:

Screen Shot 2013-05-01 at 10.17.53 PM

Leave a Reply

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