Image handling is a subject that has become more complex recently, as responsive images are now more widely supported and are encouraged to support newer retina devices and to save bandwidth for mobile users. I think it would be worthwhile to have a section under Markup that deals with how we should implement images on sites.
I have a very rough draft here on what this section could include, and I'd like to get some more input on this before creating a pull request:
Responsive Images
10up recommends the use of SVG (with an icon font fallback as needed) to serve high-resolution assets at the smallest file size possible. When using SVG you should always provide a fallback such as a PNG image for browsers that do not support vector graphics. [this sentence was moved from Progressive Enhancement section]
For user-uploaded content images, responsive images should be used in order to serve both high-resolution images to high-density devices and to avoid sending unneeded data to mobile devices. To follow the latest standards, responsive images should be served with srcset
rather than <picture>
, as long as the same image is being served at multiple sizes. If different images are being served at different resolutions, then <picture>
should be used.
At this time, not even all current browsers don't support the complete srcset
syntax, so the Picturefill polyfill is recommended to support the standard syntax. This is an exception to our guideline of using only the polyfills for features that are functionally critical to the site.
An example is shown below:
https://gist.github.com/zrothauser/a8e27f68d4ccdfb9881c
which would result in a syntax of:
https://gist.github.com/zrothauser/a58d1d3cf4cc3f285a85
Lazy Loading
In order to save on bandwidth, lazy loading images is recommended for archive pages or any page with a series of images.
[elaborate on this? or do we need this section?]
Image Sizes
The fewest image sizes needed should be defined with add_image_size
to avoid adding too much time to the upload process and to avoid using too much server space. However, most images should include a doubled size (e.g., 'home-thumbnail-double'
to go with 'home-thumbnail'
) to supply a high-density image for srcset
images.
[do we want to recommend Photon from Jetpack on non-VIP sites? It's included on VIP]
[are there any other subsections we could add to this?]