-
Notifications
You must be signed in to change notification settings - Fork 35
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
Empty source set should be allowed #243
Comments
I think this was intentional to have a story for future extensions. Can you elaborate on the use case? |
As I understand it, the use case would be a Web site where the wide viewport breakpoints includes certain content images that are not present in narrow viewport breakpoints. So, images that today have a |
Interesting. How about we return empty source set if srcset is absent, but continue the algorithm if srcset is present but does not result in any parsed image sources? That would satisfy the use case and have the same forward compat story. |
Although since srcset parsing mostly ignores unknown descriptors, it seems like it won't return an empty source set anyway for future extensions to srcset. So maybe we can stop the algorithm when srcset is present also... |
Another issue here is that if the make the algorithm return an empty source set, I think that will result in an error event being fired and alt text showing up (or broken image icon). I guess that's not quite the wanted result. |
It's probably something authors can live with ( |
Yeah. So what is the ideal behavior? Fire |
I think this is blocking on https://www.w3.org/Bugs/Public/show_bug.cgi?id=26702 for a proper fix. |
Ah man, I am super not into the idea of showing/hiding an image completely using -1 to changing behavior to accommodate this. |
I was under the impression that we have discussed it in the past as a valid use case, but maybe I was hallucinating... I guess that authors can do this by setting the src to some 1x1 transparent GIF, that would expose this as the hack that it is. |
@Wilto's argument that images that are hidden in some layouts are probably not content images seems compelling. But it's hard to know without having real examples to study. Moreover, images that are hidden in some layouts seem like they will not be critical in the layouts where they are visible, either, so it should be fine to use So lacking examples and the fact that it's easy to work around (don't even need 1x1 GIF, just use |
@aarongustafson - Can you share real-life use-cases for this? I'd prefer not forcing authors to got through data-URI copy-pasting for valid use-cases. Reopening, since I think we need to discuss this some more. |
FYI: We had similar request for our Drupal 7 picture module and we added an option so people could select 'empty image', in the back we output a data-URI, but I agree doing this by hand is optimal. I think their main use case was to be able to hide certain image fields on smaller viewports. |
I am working on the use case piece and will post here as soon as it's ready. On Wednesday, March 11, 2015 at 12:47 AM, Peter Droogmans wrote:
|
I had opened up a SO question about this very thing and have ended up here. I believe the best use case is that on some devices (mostly mobile) you will want to load/parse/cache no image. This would not be a display:none; situation. It would need to be an My argument was that if the picture source for a specified size was empty it should load no image for those devices. |
@BenRacicot thanks. You say what your wanted behavior is, but I also want to know why. Is it only to save bandwidth? Is it only to save space? (If the former, why not show the image if it's already cached?) Can you elaborate on why "This would not be a display:none; situation. It would need to be an |
Hey @zcorpan , Once an empty img src loads, we could then define via CSS if the img tag itself is display:none; to hide alt text etc. I found it surprising that this isn't even an option right now. |
@BenRacicot OK, it seems you are reasoning around the current behavior of only setting display:none. But we're here to change the spec. We can make no image be loaded and hide the image (as display:none), if that is the behavior that we want. Or not hide the image by default, if that's better. This is why I want use cases and actual examples. |
Ah I see. Yes a UI Developer I am sometimes tasked with site speed. Loading smaller images on mobile devices is great for reducing size but sometimes actually omitting content on these devices is preferred. So regularly I believe developers would utilize loading nothing on mobiles, a medium sized image on tablets and large on desktops. Please let me know how else I can help. |
It is not clear for me how this discussion ended and I can not find any hints in the docs about how to NOT load images on e.g. smaller screens. This is a very common use case, did this really find no way into the specs? |
@COLABORATI I agree. All went quiet exactly 1 year ago. I'm still very surprised that loading no image on mobile is not part of the specification for If anyone comes across some information or how we can influence the spec in this regard I would love to give my time to this. Please post back here. |
OK, wait - I want to be really sure that I am not misunderstanding things here. Yes, I found the SO question mentioned here, that feels a little hacky, but it seems to work. However, an official way of doing that would be nice. Such a long process and they really missed that? |
Yep. Lots of things are missing! Baby steps, we can't do everything at the same time. This use case was not considered a requirement (more "nice to have"), and e.g. @Wilto above disagreed we should have it at all. Maybe the time is ripe now to try again, though; it's not too late to add things. I recommend checking if an implementor is interested in working on it (we have @yoavweiss in this thread but can also file bugs/feature requests for Gecko and MS Edge). |
I see no logic in the argument of @Wilto at all - in a normative discussion it does not matter if a picture is considered "decorative" or not - the discussion should be based on facts and requirements, not speculations about the designers decision process. Fact is that it is a good recommendation to load as few pictures as possible for mobile users - but of course on a full hd desktop screen everybody likes to show a lot of great pictures. So the requirement that follows is to have a way to set "no picture" as an alternative source for the image tag. I am not trained in how to write technical specs, but I hope it is clear what this is about. Please ask, if not. |
Agreeing with @aarongustafson. I'm from germany, it's actually very common here, that our mobile data plans have a limited volume. If that is used up, our speed is reduced from 4G/LTE/whatever to about 16-64kbit/s (depending on the provider). Therefore it would be actually quite useful to stop loading images right away. I would prefer using an optional
The default behaviour: displaying nothing, as if there is no element at all (css As already mentioned, usecases would be websites, which have images as a part of their layout on larger screens (header/teaser images for news articles), but don't want/have to display them on small mobile devices to improve page speeds and reduce data usage on both ends (server doesn't have to send the image, user doesn't have to receive it). It's totally ok to be considered a nice-to-have. But since this whole
I partly agree with you, @jeremyzahner. If we can tell the browser to load images of different quality/size for different device-sizes, we should also be able to tell the browser to load no image at all for a specific |
@RicoBrase Isn't that what the CSS visibility property is for? 😄
@aarongustafson You are totally right. I'm just not sure if this use case should be solved by the picture element itself. Since the use case is heavily based upon the context (content vs. nice to have), shouldn't it be solved in the context (by CSS for example)? |
@jeremyzahner As long as that is considered for the browser to be "visible to the user" and loads the image initially, than yes, you are right. 😉 (Just assuming your idea would be actually used by a current browser.) But that's another topic basicly and should not belong here. 😉 |
@RicoBrase Actually visibility is not my idea, it has been in the spec for a long time. https://www.w3.org/TR/CSS2/visufx.html#visibility I'm not quite sure on image loading behaviour by current browser concerning visibility.
If we might come to the conclusion that some issues should be solved by another spec rather than this one, than that point belongs here (i guess?). |
I know that there is a css property called 'visibility'.
In your "concept" of a browser not loading invisible images, this should only affect images, that were set to Therefore i think, this behavior change (allow empty Side note:
We now have the ability already, to choose between different image resolutions (or completely different images at all) natively in HTML. Why should we "outsource" the functionality to load no image at all to CSS now? Your points are valid though, it should be considered (as i said a few lines above) to implement both things, since both ways are absolutely possible. But I personally think it is more intuitively (for me and other programmers/designers) to be able to have the option to load no image inside of a |
@RicoBrase @jeremyzahner You can also read these: |
@aFarkas
|
I like the arguments here. It seems the opinions are split. However I'm still not seeing the complete logic where @aarongustafson About content vs context: I agree and believe that the developer is responsible for this. Why is the spec determining what will be displayed/hidden? I also believe that the world-wide bandwidth issue should overrule the content vs context argument. Either way an empty To add to the above: @aFarkas I agree about CSS. It's a dead end to control network calls. A |
I think the first step here is deciding that avoiding to display an image in certain viewports is a valid use-case. That use-case can now be served by adding a valid data-URI as the Once we have agreement, I think the simplest way to enable that use-case is to change the processing model algorithm to accommodate that (assuming this is still Web-compatible), or add an opt-in attribute if such a change can no longer be made. @Wilto - what do you say? |
I would like to check if this use case is served well-enough by adding declarative lazy loading (and for such images, not load at all when they are |
@RicoBrase @aFarkas Maybe I lost it a little playing the devils advocate here. I totally agree on @yoavweiss' claim that we should agree on the use-case beeing present. I think it is. |
@zcorpan Method 1: If a web designer/developer (or a newbie in this topic) first hears about the Pro: most intuitive Method 2: The next logical thing to is to use an attribute, because that's what they are made for. Change or add behavior to an element (example: Pro: the 'logical' way, could be implemented for any 'resource type' element (maybe for future elements, who knows?) Method 3: The CSS way (prevent loading images with css property Pro: Would add expected behaviour to browsers Feel free to add or correct anything, i missed or got wrong. It may help to find the 'best/perfect/ideal' design for this 'problem'. 😉 @jeremyzahner |
This would also mean, that this pattern shouldn't be used in those cases, where the image is a "hero image" or otherwise initially in view and important for the first layout impression. plus: If you open the auto sizes pandora box it will be used - always. |
I got a use case recently, where a site owner would like to show some complex diagrams on viewports large enough, but provide only a download link on smaller ones. A |
Nope, the contents of (I just had to look this up for a CSS thing; I was under the same mistaken impression you were last week.)
Nope on this either. :( |
@tabatkins I was getting together a demo on CodePen late last week and realized that was the case. The empty |
I've just had the same requirement from a client as many of you here. Save bandwidth on mobile by removing images, but include them on larger screens where the connection is faster. @tabatkins @aarongustafson @nhoizey @yoavweiss @zcorpan Image TagWorks as normal
nosrc attribute is ignored if srcset is not used and works as normal
If we use srcset as normal. The same behaviour is expected.
If we use srcset and the nosrc flag. I would expect the browser to ignore the old src attribute. And would first look at srcset. If no match is found instead of defaulting to src, it would accept the nosrc flag and load no image.
Picture TagFor picture, specifying the attribute in the main picture tag would direct newer browsers to ignore the img tag and instead load no image.
|
@vipickering Just to summarize your idea:
Sounds like a good idea to me. |
@RicoBrase I agree with your two breakdowns of empty I can't help but cringe a little when I see the attribute concept. Albeit it gets the job done. However, an empty |
@BenRacicot True. I fully agree. An empty |
@vipickering I don't understand this example: <img
srcset="
elva-fairy-320w.jpg 320w,
elva-fairy-480w.jpg 480w,
elva-fairy-800w.jpg 800w"
sizes="
(max-width: 320px) 280px,
(max-width: 480px) 440px,
800px"
src="elva-fairy-800w.jpg"
nosrc
alt="Elva dressed as a fairy"> When would the Maybe this would be more relevant, to load no image on viewports <img
srcset="
elva-fairy-320w.jpg 320w,
elva-fairy-480w.jpg 480w,
elva-fairy-800w.jpg 800w"
sizes="
(min-width: 320px) 280px,
(min-width: 480px) 440px,
(min-width: 960px) 800px"
nosrc
src="elva-fairy-800w.jpg"
alt="Elva dressed as a fairy"> Anyway, I find it not so self-explanatory to have another attribute "outside" the What about this: <img
srcset="
elva-fairy-320w.jpg 320w,
elva-fairy-480w.jpg 480w,
elva-fairy-800w.jpg 800w"
sizes="
(min-width: 320px) 280px,
(min-width: 480px) 440px,
(min-width: 960px) 800px,
nosrc"
src="elva-fairy-800w.jpg"
alt="Elva dressed as a fairy"> |
@nhoizey so this is strange, I haven't been getting mentions on this issue for some reason and 4 years later I randomly get one! What your proposing looks good to me :-) |
@vipickering this is "only" 3 years later. I know we're all looking forward to a new year without this pandemic… 😅 |
One year later, how can we make progress on this? Reading the thread once again, I noticed the It should be like this: <img
srcset="
elva-fairy-320w.jpg 320w,
elva-fairy-480w.jpg 480w,
elva-fairy-800w.jpg 800w"
sizes="
(min-width: 960px) 800px,
(min-width: 480px) 440px,
(min-width: 320px) 280px,
nosrc"
src="elva-fairy-800w.jpg"
alt="Elva dressed as a fairy"> Anyway, I now have a use case when the In that case, I wouldn't be able to use a So I'm back to this: <picture>
<source
media="(max-width: 767px)"
srcset="data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACwAAAAAAQABAAACAkQBADs="
/>
<img
src="elva-fairy-320w.jpg"
alt="text alternative"
srcset="
elva-fairy-320w.jpg 1x,
elva-fairy-480w.jpg 1.5x,
elva-fairy-640w.jpg 2x,
elva-fairy-960w.jpg 3x
"
/>
</picture> (Currently, with no Writing this, I now have another suggestion, with the <img
media="(min-width: 320px)"
src="elva-fairy-320w.jpg"
alt="text alternative"
srcset="
elva-fairy-320w.jpg 1x,
elva-fairy-480w.jpg 1.5x,
elva-fairy-640w.jpg 2x,
elva-fairy-960w.jpg 3x
"
/> |
Hello everyone, yes I am still monitoring this as well. What steps can we make to get this into an official spec proposal? |
Filing a new issue with a summary at whatwg/html seems like a good next step. |
Also, an HTTPArchive analysis that shows that this won't impact existing content negatively can go a long way to ensure us this is safe to do. |
While talking to @colinbendell, he mentioned a use case he has: loading certain images only on some viewport sizes, but loading nothing on others.
My response was that this should be possible by eliminating the
srcset
attribute from that<source>
, but it doesn't seem like we specced it that way. Unless there's some other way to answer thzt use case, we probably should.Can we modify https://html.spec.whatwg.org/multipage/embedded-content.html#the-img-element:attr-picture-source-srcset-3 so that a lack of
srcset
would result in a returned empty source set?I hesitate regarding 5 there. What should we do if there are no candidates?
The text was updated successfully, but these errors were encountered: