{{ !articles[0].partner.isSponsoringArticle ? "Platinum" : "Portal" }} Partner
architects,high-perf,web design,performance,tips and tricks

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

Run a test using webpagetest:

Screen Shot 2013-05-01 at 10.17.40 PM

Found this link on different options to pngcrush:

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; \

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:


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


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 {{ articles[0].authors[0].realName }}, DZone MVB. (source)

Opinions expressed by DZone contributors are their own.

{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks