zarino / zarino.co.uk

A personal blog
https://zarino.co.uk
Other
4 stars 0 forks source link

Optimise images #23

Closed zarino closed 8 years ago

zarino commented 8 years ago

Check images in /assets and /media are at optimum size (700px max?) and quality.

zarino commented 8 years ago

Images from /media are always served 700px wide. Some are currently 1400px wide, and a few are probably some random size between. It would be a shame to lose the 1400px images on HiDPI screens, so maybe <img srcset> is the answer?

There are already a few jekyll responsive image plugins, but they mostly use the <picture> tag, expect to generate the different image resolutions themselves from a single high-res original, and introduce quite a bit of overhead. I wonder whether a quick custom-written plugin that simply takes input like this:

{% img "This is an image" /media/example.jpg /media/example-1400.jpg %}

And outputs HTML like this:

<img alt="This is an image" src="/media/example.jpg" srcset="/media/example-1400.jpg 1400w" sizes="(min-width: 768px) 700px, (min-width: 480px) 420px, 100vw">

Would do the job?

If a second image URL isn't provided, it could just output a standard img tag, no worse than we currently have.

zarino commented 8 years ago

https://css-tricks.com/responsive-images-youre-just-changing-resolutions-use-srcset/ https://mattwilcox.net/web-development/keeping-srcset-and-sizes-under-control https://ericportis.com/posts/2014/srcset-sizes/

zarino commented 8 years ago

Using Google’s PageSpeed Insights, it looks like pull request #25 improved the homepage from

to

and a fairly image-heavy individual post page from

to

The main things it now complains about are: