{"id":954,"date":"2013-05-02T01:48:47","date_gmt":"2013-05-02T01:48:47","guid":{"rendered":"http:\/\/garysieling.com\/blog\/?p=954"},"modified":"2013-05-02T01:48:47","modified_gmt":"2013-05-02T01:48:47","slug":"halving-page-load-time-with-pngcrush","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/halving-page-load-time-with-pngcrush\/","title":{"rendered":"Reducing page load time by 75% with pngcrush and Apache caching"},"content":{"rendered":"<p>Run a test using webpagetest:<br \/>\n<a href=\"http:\/\/www.webpagetest.org\/\">http:\/\/www.webpagetest.org\/<\/a><\/p>\n<p><a href=\"http:\/\/172.104.26.128\/wp-content\/uploads\/2013\/05\/Screen-Shot-2013-05-01-at-10.17.40-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-961\" alt=\"Screen Shot 2013-05-01 at 10.17.40 PM\" src=\"http:\/\/garysieling.com\/blog\/wp-content\/uploads\/2013\/05\/Screen-Shot-2013-05-01-at-10.17.40-PM-578x429.png\" width=\"578\" height=\"429\" \/><\/a><\/p>\n<p>Found this link on different options to pngcrush:<br \/>\n<a href=\"http:\/\/www.webupd8.org\/2009\/11\/compress-png-files-with-pngcrush.html\">http:\/\/www.webupd8.org\/2009\/11\/compress-png-files-with-pngcrush.html<\/a><\/p>\n<p>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:<\/p>\n<p>First, make a backup of the wp-content\/uploads directory. Then in uploads do this:<\/p>\n<pre>for file in `find . -name \"*.png\"`;do \\\necho $file; \\\npngcrush -rem allb -brute \"$file\" tmp_img_file.png; \\\nmv -f tmp_img_file.png $file; \\\ndone;<\/pre>\n<p>To add caching to Apache:<\/p>\n<pre>sudo a2endmod disk_cache\nmkdir cache\nchmod u+w cache\nchown apache-user:apacheuser cache<\/pre>\n<p>Add the settings from here to apache2.conf:<br \/>\n<a href=\"http:\/\/www.philchen.com\/2009\/02\/09\/some-tuning-tips-for-apache-mod_cache-mod_disk_cache\">http:\/\/www.philchen.com\/2009\/02\/09\/some-tuning-tips-for-apache-mod_cache-mod_disk_cache<br \/>\n<\/a><\/p>\n<p>&lt;pre&gt;<\/p>\n<p>CacheRoot \/somewhere\/cache<br \/>\nCacheDefaultExpire 3600<br \/>\nCacheEnable disk \/<br \/>\nCacheDirLevels 2<br \/>\nCacheDirLength 1<br \/>\nCacheMaxFileSize 1000000<br \/>\nCacheMinFileSize 1<br \/>\nCacheLastModifiedFactor 0.1<br \/>\nCacheMaxExpire 86400<br \/>\nCacheStoreNoStore On<br \/>\nCacheStorePrivate On<\/p>\n<p>&lt;\/pre&gt;<\/p>\n<p>Note he has some settings duplicated. I also feel that the default cache timeouts may be low for a blog &#8211; 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.<\/p>\n<p>Overall this has a similar effect to installing Varnish as a cache &#8211; 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.<\/p>\n<p>To make WordPress work, &#8220;<tt>RewriteRule . index.php [L]<\/tt>&#8221; into &#8220;<tt>RewriteRule ^(.*)$ index.php\/$1 [L]<\/tt>&#8220;. This ensures URL parameters are passed through, without which a lot of things cache as the same thing, when they shouldn&#8217;t.<\/p>\n<p>You should also add this to the Apache configuration &#8211; this prevents sending gzipped content to clients that don&#8217;t support it.<\/p>\n<p>Header append Vary: Accept-Encoding<\/p>\n<p>Here&#8217;s the final result:<\/p>\n<p><a href=\"http:\/\/172.104.26.128\/wp-content\/uploads\/2013\/05\/Screen-Shot-2013-05-01-at-10.17.53-PM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-962\" alt=\"Screen Shot 2013-05-01 at 10.17.53 PM\" src=\"http:\/\/garysieling.com\/blog\/wp-content\/uploads\/2013\/05\/Screen-Shot-2013-05-01-at-10.17.53-PM-578x429.png\" width=\"578\" height=\"429\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Run a test using webpagetest: http:\/\/www.webpagetest.org\/ 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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.garysieling.com\/blog\/halving-page-load-time-with-pngcrush\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Reducing page load time by 75% with pngcrush and Apache caching&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[535],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/954"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=954"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/954\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=954"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=954"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=954"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}