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
Add apos.images.srcset method #805
Add apos.images.srcset method #805
Conversation
Short and sweet, it mostly serves as a convenience, but it can be very convenient indeed.
This change also introduces the `sizesAttr` option that can be passed to the apostrophe-images-widgets module to set the sizes attribute of the resulting <img> element/-s. That attribute defaults to '100vw'.
@boutell @austinstarin thoughts on this? I realize that while |
I think you're right, it should move to apostrophe-images.
…On Fri, Feb 17, 2017 at 8:53 AM, Fredrik Ekelund ***@***.***> wrote:
@boutell <https://github.com/boutell> @austinstarin
<https://github.com/austinstarin> thoughts on this? I realize that while
apos.attachments.src serves the same purpose for all types of
attachments, this method is only applicable to images. Perhaps then it'd
make more sense to move it to apostrophe-images?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#805 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAB9fSsK5QpjrlODfWTWLfrugIZtQ5zGks5rdaZGgaJpZM4LupMY>
.
--
*THOMAS BOUTELL, *SUPPORT LEAD
P'UNK AVENUE | (215) 755-1330 | punkave.com
|
Cool, I'll have a look at moving it! |
It makes sense to place it there rather than in apostrophe-attachments, since srcset attributes can't be calculated for other types of attachments.
@boutell moved! It's now |
Hi Fredrik, We had a long discussion about this just now. We think it is a very, very cool idea but unfortunately there are some significant issues with it. First, the code assumes that "sizes" should be set to 100vw. This works out pretty well on a phone, because generally any columns etc. have collapsed to one column in that setting. So the image that gets picked matches the device size and we're good. But on a desktop it's bad news, because 100vw will be very large, even if this image widget is actually going into one of five columns and should therefore be very small. As a result the We could add a Finally, and this is arguably our fault, although some shaping and styling tricks are very difficult any other way... we use CSS background images a lot. In that scenario the img element is pretty much there for SEO. And when that is happening the srcset doesn't have much use. @austinstarin just showed me an example of a client project where he built his own So for now this is not something we're going to do. But we're open to an ongoing conversation about what we might be able to do to help frontend developers use srcset effectively without making unsafe assumptions about their use cases. Thanks and please continue sending PRs! |
Thanks for the detailed feedback, feels good to engage in an open source project with such a positive attitude! As for the points you bring up - I see the issue with the However, if you still feel that it's not worth including the apostrophe-images-widgets markup, then I won't fight for it. I think it would be neat to have, but I also believe people will be writing their own custom image modules for different scenarios, and can then decide for themselves whether or not to include those attributes. But I do feel more strongly about including the So, what we could do is to drop the changes in apostrophe-images-widgets and just add the |
Hmm, both suggestions make sense to me... is there a straightforward way to add an option for those who want to specify "I'll pay the extra freight to go 2x on retina"? |
The retina stuff is actually handled automatically by browsers! The |
I think you're right:
https://www.keycdn.com/blog/responsive-images/
@stuartromanek, @bgantick, @austinstarin, I think Fredrik'ss suggested
revisions makes sense, including folding it into the standard images
widget. We already use the `size` option to communicate about how big we
think the image is going to be, so we ought to be able to build a correct
`sizes` attribute on that basis. And it would match what Wordpress is doing
successfully in this area. What do you think?
…On Sun, Mar 5, 2017 at 9:27 AM, Fredrik Ekelund ***@***.***> wrote:
The retina stuff is actually handled automatically by browsers! The srcset
attribute has gone through one or two revisions since it was introduced,
and the 2x syntax is no longer needed. And I don't really know of any way
to turn off the retina consideration - I think browsers will try to pick
the picture that will look best within some confines. For example, if your
viewport is 1000px wide and you have two image options - one 800px and one
2000px, I believe most browsers will pick the smaller one, because 2000px
is deemed unreasonably large to justify a download.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#805 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAB9fZa3fWCitxjiaGFy5gXUSNL1wDjDks5risZrgaJpZM4LupMY>
.
--
*THOMAS BOUTELL, *SUPPORT LEAD
P'UNK AVENUE | (215) 755-1330 | punkave.com
|
Consensus here is that your revised suggestions make good sense! Do you want to take a crack at these changes? The dimensions for each named size are available in the attachments module. |
Great – happy to hear it! Absolutely, I'll have time to look into it in a day or two. Do you want to reopen the PR in the meantime? :) |
Follow the same pattern that WordPress does, ie. (max-width: {{image-width}}px) 100vw, {{image-width}}px This gives us sharp images, but also makes sure that users on desktop won't have to download bigger images than with previous Apostrophe versions. Also updated CSS after having tested the widget - background images are no longer used on .apos-slideshow-item's. If we continue to use that, we won't see any benefits from the srcset implementation.
There we are! I've updated the default value of the I did some testing as well and concluded that we have to drop the current background-image solution on the |
The sudden disappearance of the background images would definitely be a
disruption for production websites that don't happen to override
widget.html and have CSS dependent on that technique, so that's something
we won't be doing at least without a flag to that effect.
Background images are generally used to achieve responsive autocropping and
leverage background-size: cover, among other effects that the img element
is just not very good at.
…On Fri, Mar 10, 2017 at 9:29 AM, Fredrik Ekelund ***@***.***> wrote:
There we are! I've updated the default value of the <img>'s sizes
attribute in apostrophe-image-widgets.
I did some testing as well and concluded that we have to drop the current
background-image solution on the .apos-slideshow-items for srcset to be
effective, so I did that and updated the CSS accordingly. I did some manual
testing besides the unit test I added for the new apos.images.srcset
method, and things look to be working well both for single images and
slideshows, but please do have an extra look at the diff before merging to
make sure I don't break any of your assumptions in
apostrophe-images-widgets.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#805 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAB9ffTHymdSCkFuH1JVoxhPG6BvTRyTks5rkV5dgaJpZM4LupMY>
.
--
*THOMAS BOUTELL, *SUPPORT LEAD
P'UNK AVENUE | (215) 755-1330 | punkave.com
|
Hmm well that's a problem then. I guess we could hide the new behavior behind a widget option (eg. |
After having mulled this over a bit, I think that the added complexity we would introduce by adding a |
@stuartromanek @bgantick @austinstarin, I'm coming back to this now and am still thinking like my last comment. If P'unk Avenue relies on using background images over I can't stress enough the value that this underlying functionality brings - for websites that demand ease of content editing, good performance for end users and high image quality - Apostrophe might actually have it all. The image variations that are already there just need to be exposed through some template functions (and those template functions need to be documented), and voíla! |
Yes, I think the key thing here is a HOWTO to go with it.
…On Wed, Nov 8, 2017 at 4:05 PM, Fredrik Ekelund ***@***.***> wrote:
@stuartromanek <https://github.com/stuartromanek> @bgantick
<https://github.com/bgantick> @austinstarin
<https://github.com/austinstarin>, I'm coming back to this now and am
still thinking like my last comment. If P'unk Avenue relies on using
background images over <img> elements, then the best way forward would
probably be to drop the updated CSS and markup in
apostrophe-images-widgets, and instead just add the apos.images.srcset
and the apos.attachments.getImageSize methods.
I can't stress enough the value that this underlying functionality brings
- for websites that demand ease of content editing, good performance for
end users *and* high image quality - Apostrophe might actually have it
all. The image variations that are already there just need to be exposed
through some template functions (and those template functions need to be
documented), and voíla!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#805 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAB9fVCASTQPKa465PQ-C_vJc-LUesovks5s0heCgaJpZM4LupMY>
.
--
*THOMAS BOUTELL, *SUPPORT LEAD
P'UNK AVENUE | (215) 755-1330 | punkave.com
|
We should definitely be moving this direction in Apostrophe (and move away from background images as a default). Thanks for the hard work @fredrikekelund @fredrikekelund can you take a crack at re-writing the first part of this document to go over the features? https://github.com/punkave/apostrophe-documentation/blob/master/tutorials/howtos/responsive-images.md |
@stuartromanek sure! Will see if I can look into it over the next couple of days. I assume you don't want me to make any further changes to |
Not at this time @fredrikekelund .. next week I want to round up with a few other Apostrophe devs to go over internally, will let you know how that shakes out. |
95ca213
to
24e0d4b
Compare
@stuartromanek @boutell I actually went ahead and reverted all of the changes to apostrophe-images-widgets - making it so the only changes here are the introduction of the I think it's more valuable to merge those methods, showing clearly that Apostrophe supports srcset more or less out of the box, than it is to find a way forward going from a Happy to add documentation about those methods in the tutorial chapter that you mentioned @stuartromanek, if you like? |
To make sure we don't forget: we should close this PR once we merge this as well apostrophecms/apostrophe-documentation#45 |
Bumping this PR again @stuartromanek and @boutell 😇 As a quick recap: we went around the whole
|
@stuartromanek given that this doesn't change the standard behavior of our widgets, do you see any objection to merging it? We could then provide a HOWTO on how to do srcset at project level. @fredrikekelund it sounds like getImageSize has no remaining application here? |
No objection here, I'd like a second look from some of the other Apostrophe front-end'ers who might be implementing this sort of behavior project-by-project and see if it satisfies their normal requirements. |
@boutell I removed the I also merged the latest master, so the branch should be mergeable now! |
merged |
🙌 |
This PR was opened as a complement to apostrophecms/apostrophe#805. But since the outcome of that PR was not to add a srcset feature directly to apostrophe-images-widgets (but rather to introduce just a template helper `apos.images.srcset`), this change adds a section to the "Responsive images" how-to about how to write a simple widget that renders an `<img>` tag with a srcset attribute.
Here's the
apos.attachments.srcset
method (with an accompanying test) discussed in #803. The srcset attribute is fairly simple, so there's not much to it. I changed my mind on the naming of thesizes
attribute passed to apostrophe-images-widgets, though, so it's nowsizesAttr
. It seemed like this would cause less confusion with the existingsize
option.One thing that I think warrants some discussion is the possible inclusion of the picturefill.js polyfill. The only browser that doesn't support srcset is IE, but picturefill.js really just works and weighs in at a pretty small 11.5 kB when minified. Maybe this is the kind of thing better left to individual developers (perhaps the possibility of including it could be mentioned in the docs), but I wanted to throw it out there.
I'll go ahead and submit a PR to the docs for this as well.
Btw, it looks like some trailing whitespace was removed automatically by my editor, but I didn't think that caused any harm.