Since there’s a lot of development going in the responsive images field right now, I was wundering how I can combine the new <picture>
markup method of the new Picturefill 2.0 polyfill with a plugin like WP Retina 2x.
Basically I have been using the WP Retina 2x plugin to render the @2x retina images in the media library and showing them on retina displays using the Retina.js method in the settings. That worked however it caused images to download twice on retina displays, where Picturefill 2.0 is designed to avoid that.
On a new WordPress project I switched to the new <picture>
markup described here and am trying to implement it with retina images too.
<?php
$image = get_field('featured_image');
$alt = $image['alt'];
$imgsrcmd = $image['sizes']['medium'];
$imgsrclg = $image['sizes']['large'];
?>
<picture>
<!--[if IE 9]><video style="display: none;"><![endif]-->
<source srcset="<?php echo $imgsrclg; ?>, <?php echo $imgsrclg; ?> 2x" media="(min-width: 480px)">
<source srcset="<?php echo $imgsrcmd; ?>, <?php echo $imgsrcmd; ?> 2x">
<!--[if IE 9]></video><![endif]-->
<img srcset="<?php echo $imgsrclg; ?>, <?php echo $imgsrclg; ?> 2x" alt="<?php echo $alt; ?>">
</picture>
If I use the above markup, which of the WP Retina 2x methods should I use:
- HTML srcset (W3C Draft)
- HTML Rewrite
- Retina.js
- Retina-Images
- None
The HTML srcset method is the best. The HTML will be rewritten with the srcset attribute added to the img tags. Works with caching. Unfortunately, not all the browsers support it yet.
The HTML Rewrite method is one of the best methods. It replaces the images by the retina images - if available - in the HTML directly. It’s tricky to use HTML caching with it however.
The Retina.js method is fail-safe and only uses one JavaScript file. When a Retina Display is detected, requests for every images on the page will be sent to the server and the retina images will be retrieved if available. Requires a lot of bandwidth.
The Retina-Images method is efficient. The images will go through the Retina-Images handler. Caching systems might be an issue.
Because none of them seem to work yet.
Somehow the 2x markup should tell the plugin to look for the @2x retina version of the image in the media folder, but it doesn’t obviously…
Does anyone else found a way or workflow to let these two techniques play nicely together?
Many thanks!