Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Srcset support #1

Open
kylehotchkiss opened this issue Apr 15, 2016 · 5 comments
Open

Srcset support #1

kylehotchkiss opened this issue Apr 15, 2016 · 5 comments
Milestone

Comments

@kylehotchkiss
Copy link
Member

Srcset looks to be on it's way. It will soon be in chrome. It's already in webkit.

For others, we can polyfill and serve low res and high res:
https://github.com/borismus/srcset-polyfill

Our most common use case would be for images in a blog post, carousel, etc. We could have a low res 320px version, and then a higher res version that gets served to desktops widths.

There is some debate over what to do for retina phones, I'm pretty firmly in the "don't send them huge images over 3g/4g" camp, but that could be a point of discussion.


Just noting for the future
http://www.smashingmagazine.com/2015/02/24/ricg-responsive-images-for-wordpress/


Next version of WP is almost out and is going to have the above mentioned plugin:

For the sizes attribute, we have chosen to use sizes="(min-width: {img.width}px) {img.width}px, 100vw" as a sensible default. However, this default value can and should be filtered by themes to meet their layout needs.

Based on community feedback, we are choosing not to include a polyfill for non-supporting browsers directly in core. However, we would recommend that themes make use of Picturefill in order to provide responsive image support to the broadest set of users.

The picturefill site has some ongoing docs about various patterns, should we follow the WP syntax?

Lastly sizes support is also almost universal in browers (IE future in 13, and was added to safari 9 and ios9)
http://caniuse.com/#feat=srcset

Do we even need the polyfill?

@ccorda
Copy link
Contributor

ccorda commented May 4, 2016

Example of doing this manually using timber resize:
timber/timber#784

@jeffgreco
Copy link
Contributor

The Timber example is better, but posting this anyway https://github.com/aFarkas/lazysizes

@ccorda
Copy link
Contributor

ccorda commented Aug 23, 2016

@kylehotchkiss used lazysizes recently with imgix. could be worth doing

@kylehotchkiss
Copy link
Member Author

http://www.kylehotchkiss.com/photography/ Live Examples here

@ccorda ccorda modified the milestone: 1.0 Dec 1, 2016
@laras126
Copy link

laras126 commented Aug 20, 2017

Chiming in a year later, and srcset is here to stay! You can take advantage of the responsive images in core using the wp_get_attachment_image_srcset function if you don't want to resize them manually (which creates a lot of duplicate images in uploads/). Here's an example in a Twig template:

<img src="{{function('wp_get_attachment_image_url', post.thumbnail.id, 'medium')}}" 
         srcset="{{function('wp_get_attachment_image_srcset', post.thumbnail.id, 'medium' )}}"
         sizes="(max-width: 1024px) 100vw, 1024px" alt="Post thumbnail">

Swap out post.thumbnail.id with the id of your desired image. You can easily use lazysizes here as well by adjusting the attribute names accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants