Performance Zone is brought to you in partnership with:

Gary Sieling is a software developer interested in dev-ops, database technologies, and machine learning. He has a computer science degree from the Rochester Institute of Technology. He has worked on many products in the legal and regulatory industries, having worked on and supported several data warehousing applications. Gary is a DZone MVB and is not an employee of DZone and has posted 62 posts at DZone. You can read more from them at their website. View Full User Profile

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

05.06.2013
| 3632 views |
  • submit to reddit

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

Published at DZone with permission of Gary Sieling, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)