{"id":3384,"date":"2018-12-29T18:18:17","date_gmt":"2018-12-29T18:18:17","guid":{"rendered":"https:\/\/www.toobusyto.org.uk\/tooBusy\/?p=3384"},"modified":"2018-12-29T18:20:44","modified_gmt":"2018-12-29T18:20:44","slug":"blog-news-self-hosting-photographs","status":"publish","type":"post","link":"https:\/\/www.toobusyto.org.uk\/tooBusy\/2018\/12\/29\/blog-news-self-hosting-photographs\/","title":{"rendered":"Blog news: self-hosting photographs"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A few months ago I noticed that the home page of this site was taking multiple seconds to load. Common wisdom is that a &#8220;good&#8221; loading time is under 200ms, and even though a photo blog such as this might be a bit slower than a text-heavy site, multiple seconds is just too long to wait.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The best lead I had as to why this was taking so long was the comment inserted by the <a href=\"https:\/\/wordpress.org\/plugins\/wp-super-cache\/\">WP Super Cache<\/a> plugin at the bottom of every page recording how long it took to generate in seconds. This was frequently more than 3 seconds which suggested that the problem was either my web server being too slow or a problem with my WordPress setup. Discounting the first as unlikely, I did some reading up on WordPress performance-tuning. The most practical advice was to minimise the number of plugins you use, and turn off each plugin in turn and check the effect on load-time before and after. I use few plugins but had been fond of <a href=\"https:\/\/wordpress.org\/plugins\/flickr-justified-gallery\/\">Flickr Justified Gallery<\/a> for displaying my <a href=\"https:\/\/www.flickr.com\/photos\/ndimmock\/\">Flickr-hosted photographs<\/a>, and of course this was the culprit. The problem is not the plugin itself but <a href=\"https:\/\/wordpress.org\/support\/topic\/very-slow-to-load\/\">Flickr&#8217;s own API<\/a>\u2014generating each gallery requires a query to Flickr to retrieve the list of photos in the album.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">My preferred solution was to host my own images. This blog is 14 years old now and as<a href=\"https:\/\/www.toobusyto.org.uk\/tooBusy\/2017\/11\/13\/repairing-broken-links-on-this-site\/\"> I learned last year<\/a>, third party services can disappear or change unexpectedly. Sadly the built-in gallery layout with WordPress 4.x remains an old-fashioned looking grid of square thumbnails that can fail to represent the underlying photograph properly (<a href=\"https:\/\/www.toobusyto.org.uk\/tooBusy\/2015\/01\/25\/nova-scotia\/\">example<\/a>). The JetPack add-on comes with a more attractive gallery layout but automatically uploads and serves all your images from their servers, which has its own downsides.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I looked at a number of third-party gallery plugins but anything outside the WordPress core also has the same &#8220;third-party risk&#8221; as Flickr: the code  could stop working in the future, breaking all my old posts. None could also match the slick efficiency of Flickr&#8217;s upload workflow for optimising, arranging and captioning images. Fortunately while I was investigating this, WordPress released their new Gutenberg Editor. This comes with a new <a href=\"https:\/\/www.toobusyto.org.uk\/tooBusy\/2018\/08\/26\/the-championships-2018-day-12\/\">Gallery<\/a>, the first version of which was a bit buggy but has the modern look that I wanted, and has improved over the last few months. (At time of writing there remains a bug where clicking on any photo in a gallery displays the first photo in the gallery not the one you clicked on. This is due to be fixed in mid-January.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Switching to the new gallery improved page-generation times but without Flickr to optimise my images, I need to do this prior to upload to keep page-load times acceptable. This involves a two-step process:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Use ImageMagick to resize images to no more than 2048 pixels on their longest edge: <tt>mogrify -resize 2048x2048 *.jpg<\/tt> (be careful, this changes the original files!)<\/li><li>Reformat to be progressive JPEGs and apply lossless optimisation. There are a number of tools that can do this but <a href=\"https:\/\/imageoptim.com\/mac\">ImageOptim<\/a> is an efficient open-source drag-and-drop option for MacOS.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The final tweak, as recommended by Google&#8217;s <a href=\"https:\/\/developers.google.com\/speed\/pagespeed\/insights\/\">PageSpeed Insights<\/a> tool, was to <em>defer offscreen images.<\/em> This should make the initial page render faster by not loading images that are not yet viewable, and was already available as part of the Jetpack add-on (<a href=\"https:\/\/jetpack.com\/support\/lazy-images\/\">Lazy Load Images<\/a>).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A few months ago I noticed that the home page of this site was taking multiple seconds to load. Common wisdom is that a &#8220;good&#8221; loading time is under 200ms, and even though a photo blog such as this might be a bit slower than a text-heavy site, multiple seconds is just too long to &hellip; <a href=\"https:\/\/www.toobusyto.org.uk\/tooBusy\/2018\/12\/29\/blog-news-self-hosting-photographs\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Blog news: self-hosting photographs&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-3384","post","type-post","status-publish","format-standard","hentry","category-geeky"],"_links":{"self":[{"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/posts\/3384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/comments?post=3384"}],"version-history":[{"count":9,"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/posts\/3384\/revisions"}],"predecessor-version":[{"id":3394,"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/posts\/3384\/revisions\/3394"}],"wp:attachment":[{"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/media?parent=3384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/categories?post=3384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.toobusyto.org.uk\/tooBusy\/wp-json\/wp\/v2\/tags?post=3384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}