News

Add new post

Florian’s Compromise

I’ve been fairly quiet in this group for a while now. Part of that was wanting to let the dust settle on all the chaos that was surrounding this topic a few short weeks ago, and part of that was giving myself some time to digest the bits of signal that came through amidst all the “responsive images” noise.

More and more it seems that it’s a waste of effort trying to retrofit the original srcset proposal to cover all the use cases of the original picture proposal. As we attempt to do so, the srcset microsyntax grows and more and more confusing, and shares an increasing amount of overlap with media queries. To those ends, I asked Florian Rivoal — editor of the media query spec — to join the discussion on the WHATWG mailing list and offer his perspective.

Florian joined the list by posting a brilliantly thought-out compromise between the two syntax patterns. I’d like to share my thoughts on this proposal here, as I feel it combines the strengths of srcset and picture in a practical and logical way.

Let’s begin by taking a look at the proposed syntax.

Sample Markup Pattern


<picture alt="Description of image subject.">
  <source srcset="small.jpg 1x, small-highres.jpg 2x">
  <source media="(min-width: 18em)" srcset="med.jpg 1x, med-highres.jpg 2x">
  <source media="(min-width: 45em)" srcset="large.jpg 1x, large-highres.jpg 2x">
  <img src="small.jpg" alt="Description of image subject.">
</picture>

The chain of events followed by the above markup pattern are:

  1. If the picture element is unsupported, the img contained therein is shown as fallback markup.
  2. If picture is supported, use media attributes to determine which source element best suits the user’s viewport.
  3. Once an appropriate source element has been selected, the srcset attribute determines which image source is best suited to the user’s screen resolution. If only a single resolution is necessary, the src attribute will function as expected.

In terms of selecting a source element, this markup leverages all the strengths of media queries — the syntax created for this very purpose — to handle the “art direction” use case that Jason Grigsby has illustrated so eloquently.

However, as has been detailed at length on the WHATWG mailing list and elsewhere, device-pixel-ratio media queries are poorly suited towards these decisions. As an author, using vendor-prefixed min-device-pixel-ratio media queries in the example above would involve a massive amount of text and twice as many source elements. This could get unwieldy for authors very quickly, a concern voiced numerous times in these ongoing discussions. Further, implementation of MQ-based resolution switching is far more difficult on the UA side: a very real concern.

Once we’ve used media queries to determine the most appropriate source element, srcset’s originally intended usage becomes absolutely ideal for our purposes: simply determining the appropriate image source for a user’s resolution.

It’s worth noting that this example is, in fact, the most convoluted this element can ever be. This pattern in no way precludes the use of srcset on an img tag for simply preforming resolution switching, nor does it preclude the use of picture as originally proposed, with src in source elements rather than srcset.

Bandwidth

The dark cloud hanging over all these discussions is the concept of “bandwidth detection.” We cannot reliably make assumptions about bandwidth based on client capabilities — a MacBook Pro with a Retina display may be tethered to a 3G phone; a high-resolution mobile device is as likely to be connected to WiFi as it is an EDGE connection.

It would assume a great deal if authors were to make this decision for the users. It would add a point of failure: we would be taking the bandwidth information afforded us by the browser, and selectively applying that information. Some of us may do it wrong; some of us may find ourselves forced to make a decision as to whether we account for users with limited bandwidth or not. To not account for it would be, in my opinion, untenable — I’ve expressed that elsewhere, in no uncertain terms.

I feel that bandwidth decisions are best left to the browser. The decision to download high vs. standard resolution images should be made by user agents, depending on the bandwidth available — and further, I believe there should be a user settable preference for “always use standard resolution images,” “always use high resolution images,” ”download high resolution as bandwidth permits,” and so on. This is the responsibility of browser implementors, and they largely seem to be in agreement on this.

In discussing the final markup pattern, we have to consider the above. Somewhere, that markup is going to contain a suggestion, rather than an imperative. srcset affords us that opportunity: a new syntax _designed_ to be treated as such. I wouldn’t want to introduce that sort of variance to the media query spec — a syntax long established as a set of absolutes.

It seems srcset won’t be going anywhere, and that’s not an indictment. There is a time and a place for srcset. I feel that place is resolution switching, as it was originally intended. Our best efforts to bring srcset closer in-line with the originally proposed picture element only stand to leave us with a siloed microsyntax that inconsistently serves the purpose of media queries. With that comes further opportunity for errors by implementors and authors alike — countless new potential points of failure.

An Updated Polyfill

In order to better wrap my head around this pattern, I’ve updated Scott Jehl’s Picturefill to make use of the proposed syntax. The source code is available on GitHub, and I’ve posted a demo as well.

Next Steps

I’ve been discussing the implementation details of this pattern with several vendors recently, and the feedback has been extremely promising.

I’d love to hear everyone’s thoughts on this compromise, and through your feedback put together a set of formal proposals: a change proposal returning srcset to its original resolution-only syntax, and a proposal for picture that focuses on the “art direction” use case and optimization for client displays through media queries, excluding resolution.

The Constant Caveat

It seems I always end my posts in much the same way, but it always seems to ring true: this solution is not the ultimate solution to every problem in the “selectively loading assets” arena — nor does it have to be, right now.

There will always be limitless room for improvement when it comes to markup — a better way to handle source management for rich media, for example. But we can’t solve everything now — we can’t fall into the trap of seeking the perfect solution all at once.

Our goal is a laser-focused solution with the potential to fall in-line with other rich media elements, as we solve the greater issues one by one — issues of bandwidth detection; issues of organization. Our goal is to solve a very real and increasingly urgent problem, in a way that serves as a canvas for future enhancements. I’m confident that this syntax affords us that opportunity.

We can’t predict the future. We can only strive to be future friendly, while solving the problems of today. I’m confident this proposal does so.

RICG at TPAC 2012

During TPAC 2012, Yoav Weiss and I (Marcos Cáceres) had the opportunity to present the work of RICG to the W3C membership. We gave 2 presentations during TPAC:

  1. Panel discussion, on Wednesday during the Tech Plenary
  2. A one hour presentation and QA session to the HTMLWG about responsive images.

Panel Discussion

The panel discussion was organised by Odin Hørthe Omdal of Opera Software, Yoav, and I, and we were fortunate to have participation from Ted O’Conner (editor of the srcset specification) from Apple, and from Travis Leithead from Microsoft. During the session, Yoav and I presented the use cases and we did a demo using the prototype implementation. Minutes are available. After we presented, we handed the mic over to Ted and to Odin, who outlined some of the issues with relying on CSS Media Queries, as currently does, in the markup.

Ted argued that some of the use cases could be met by using CSS to crop certain images into size. Ted also pointed out that many of responsive images use cases can be addressed with other platform features: CSS filters and shaders, svg. Thus, it’s not necessary to cover every single case with a one-fits-all solution because other parts of the platform (e.g., JS libraries) can be used to achieve the 20% cases that require something more specific. As recorded in the minutes, “we might do authors a disservice by designing something that they use instead of other, more suitable features”.

Then Odin raised some good points about having a truly declarative model for responsive images: that is, one where a developer only hints at the browser what they require, and then the browser handles fetching the appropriate resource if a declared condition is met and if it’s appropriate. He argued that this is embodied in the srcset proposal. This is in contrast with the current approach proposed by the picture element, which more forcefully tells the browser what to do (through media queries). This approach opens up a number of interesting use cases (e.g., allowing the user to tell the browser to only serve them the low quality or high quality images – akin to what Opera Mini does). This approach is not without its problems, as it does not handle “art direction” well, but it’s still interesting enough that it should be added to the use cases document.

Other things that come up during the panel were related to looking at how video solves the “adaptive” problem. To me personally, this seemed a bit too experimental (i.e., might require new formats or might require doing some nasty hacks with , which would probably be no better than what we are doing today with responsive image polyfills)… but who knows! I’m no video expert, so there may be something there worth looking into (NB: just this week, Ian Devlin posted an article/test showing this working!).

As I personally found Odin’s ideas very interesting (as they pin-point to the devision between designers and browser vendors), so I asked him is he we could make a short video so we could discuss his ideas further and also give the community an opportunity to think about them:

Marcos and Odin

Responsive images use cases from Responsive Images CG on Vimeo.

HTMLWG presentation

On Thursday, 1st of November, the RICG was invited to present our work to the HTML WG. The presentation went very well, with a good set of questions being asked after we finished presenting. Unfortunately, the minutes from the HTMLWG meeting have not yet been published.

Marcos presenting to HTMLWG

RICG presents to HTML Working Group from Responsive Images CG on Vimeo.

The State of the Picture Specification

First, a little housekeeping: while the community group is site is great for ongoing discussion, it doesn’t offer anything in the way of tracking specific goals and issues. Up to this point we’ve been using a GitHub repo on my account.

It’s working great for us so far, if I may say so, and it feels good to be working on familiar turf — but it’s still tied to my admittedly nonsensical nickname. This is an effort led by the developer community, and it should be reflected as such.

I’m pleased to announce that the RICG now has a formal home on GitHub. We’ll be tracking issues and publishing drafts through this organization and its repos, while the CG site and mailing list will continue to be used for broader conversation. I hope to see you all there!

We’ve put out a call on the mailing list for anyone willing to contribute an hour or two per week to helping us triage issues and review changes — let us know if you’re willing to pitch in!

The Extension Specification

Politics aren’t my strong suit, so the current state of our proposal is a weight off my shoulders.

Both our proposal and the srcset proposal are being handled as “extension specifications,” and they’re currently being developed independent of the overall HTML spec. We’re actively working with proponents of the srcset extension specification to ensure that the two complement each other, and both our extension spec and use case documentation reflects that.

No single decision maker or group has the final word in this, as Marcos explained on the mailing list earlier today. When and if it leads to functional native implementations, it will be merged into a snapshot of the HTML spec.

The picture specification, though still in progress, is eligible for real-world implementations as we speak. We’re continuing to reach out to browser representatives to collaborate on the proposal and discussing where the picture element would fit on their development roadmaps. I’m calling on all of you to do the same. In the end, demand is the deciding factor when it comes to new features — there’s no shortage of demand for picture; we’re proof of that. Let’s make sure the browsers vendors hear from us.

A Native Implementation

We’ve reached the point in hammering out the extension specification where we’re focusing on more specific issues we’d be likely to run into in a native implementation.

It’s difficult — if not impossible — to hash out the potential issues with a real-world implementation in a vacuum. As a result, Yoav Weiss has begun prototyping a native picture element in a fork of Chromium. We’re addressing the questions that arise as a result in the issue tracker for the extension specification.

I know, for my part, it was exciting to finally see that picture’s source pattern can and will work with Chrome’s image prefetching with my own eyes. It’s one thing to talk about it on a mailing list—it’s another to see it working.

Twitter Account

As my Twitter followers know all too well: I am largely unbearable. For the sake of anyone that wants to keep tabs on ongoing developments without being subjected to dog photos and complaints about the Boston subway system, we’ve started up an RICG Twitter account: @respimg.

Thanks

I want to personally thank Marcos Caceres. Marcos has been putting a tremendous amount of time and effort into the extension specification, and into organizing the efforts of the RICG.

I also want to thank all of you, once again. We’re not only making steady progress on a long overdue solution to a very real problem, but we’re bringing about changes to the way the web is built. Our community group is being held up as a shining example of how developers can get directly involved in web standards, and we’re working with members of the W3C to find ways of smoothing out the rough edges on the process we’ve carved out. It hasn’t been especially easy or chaos-free, but we’re making things that much easier for the next group of developers that comes along with a good idea.

Blue Beanie Day is coming up. When you put one on, know that you’re not just supporting web standards — you’re taking an active role in moving standards, and the web itself, forward.

Respondu 0.0.4 – Up to date with proposed picture sytax

Hey Everyone

Just to let you all know, the Respondu framework has undergone some changes to make it cleaner, simpler and more robust.

https://github.com/davidmarkclements/Respondu

http://respondu.davidmarkclements.com

Respondu uses a different method to Scott Jehl’s polyfill, it piggy backs on the noscript idea using a hack to extract the noscript content cross-browser. This means you can use the exact picture syntax and simply precursor it with a call to Respondu and wrap it with modified noscript tags like so:

<h1> Picture Element Example </h1>
<script>Respondu(‘picture’);</script>
<noscript>
<picture id=thepic>
<source srcset=”images/photo.small.jpg 1x, images/photo.small.jpg 2x”>
<source media=”(min-width:320px)” srcset=”images/photo.medium.jpg 1x, images/photo.medium@2x.jpg 2x”>
<source media=”(min-width:640px)” srcset=”images/photo.large.jpg 1x, images/photo.large@2x.jpg 2x”>
<source media=”(min-width:1280px)” srcset=”images/photo.xlarge.jpg 1x, images/photo.xlarge@2x.jpg 2x”>
<img src=”images/photo.jpg” alt=”Alt tag describing the image represented”>
</picture>
</noscript-->
<p> Some content after the image </p>

Respondu supports the proposed the current form of the picture syntax with media and simplified (i.e. density only) srcset attributes. I can say that building this framework and using it in my projects, the new picture syntax is a pleasure compared to the img srcset syntax – if you take a look at the examples you’ll see what I mean. The picture syntax has a much nicer balance between vertical  and horizontal text length.

Thanks to all, exciting times ahead!

Call for Final Specification Commitments for Picture Element Proposal

On 2012-08-29 The Responsive Images Community Group published the following specification:

This is a call for Final Specification Commitments. To provide greater patent protection for this specification, participants in the Responsive Images Community Group are now invited make commitments under the W3C Community Final Specification Agreement by completing the commitment form. Current commitments are listed on the Web. There is no deadline for making commitments.

If you have any questions, please contact the group on their public list: public-respimg@w3.org. Learn more about the Responsive Images Community Group.

Thoughts on adding a type attribute

Matt Wilcox brought this idea up a few months ago, but the issue seemed to fall off the table and was lost in other discussions. It’s something I’d like to see get some more feedback and general discussion from other developers so I’m bringing it back up. Below are some thoughts I’ve put together for adding a type attribute to source tags in the picture element.

  • A type attribute would allow for a native HTML way to use new image formats, which could help decrease the load of image assets, increase site performance, i.e. WebP, JPEG-XR.
  • The type attribute could also be a starting point for responsive image formats. As an example, a user could specify a new responsive image format which streams its data per however that magic would work and if the new responsive image format is not supported in the browser, it could fallback to the next image in the source stack, depending on which media query is active in the source list.
  • The idea of fallback images is something that is being worked on in CSS: http://dev.w3.org/csswg/css4-images/#image-notation
  • Since the picture element markup is very similar to the HTML5 video element, it seems to just make sense to also include type attributes just like the video element.
  • I’m curious if type could be an optional attribute and only needed if you are planning to use newer image formats that would need a fallback pattern. This would be ideal so developers don’t have to specify type=”image/jpg” or type=”image/png” on each source tag
  • Adding a type attribute seems like a very future friendly and forward thinking action.

Here is a gist of this concept: https://gist.github.com/3410238

Adding the type attribute to source tags in the picture element seems to be beneficial with no apparent drawbacks. I’m sure there are some issues so feel free to let me know what your concerns and issues/drawbacks are of adding a type attribute.

`Picture` in the HTML5 Spec

Paul Cotton, one of the HTML WG Chairs, has arranged for me to work with several members of the HTMLWG on a final draft of the `picture` specification, as we discussed at the HTML WG weekly teleconference on July 26th.

picture is tentatively slated for inclusion under the HTML5 umbrella, rather than being pushed to HTML.next. The status of the proposal can be tracked via the W3C Bugtracker. I’ll be working with Adrian Bateman and Frank Oliver from Microsoft on a formal specification in the coming weeks, and will have an update on our progress by August 16th (per https://www.w3.org/html/wg/tracker/actions/220 ).

Laura Carlson has also been working to gather feedback from the HTML WG Accessibility Task Force on the proposed markup, in addition to being tremendously helpful in navigating the standards process. Welcome to the RICG, Laura!

`Picture` in Drupal 8

The Drupal team is currently discussing the inclusion of the picture markup pattern in the Drupal 8 core. They seem to be leaning towards including the proposed element itself, rather than an equivalent pattern using Picturefill. I’ve let them know that doing so may be a bit preemptive at this time. If nothing else, this further proves the developer community’s interest in this solution.

I’ve asked Jesse Beach to act as the Responsive Image Community Group’s primary contact with the Drupal team to help field implementation questions and feedback.

The Drupal team working on this issue includes (among many) John Albin Wilkins, Jeff Burnz, Lewis Nyman, Tim Plunkett, Peter Droogmans, Théodore Biadala, Rob Wierzbowski, Wim Leers, medden, Gábor Hojtsy, Sam Richard, Alex Bronstein, Marc Drummond, Bojhan, and Angie Byron.

I’m really looking forward to hashing out some real-world issues, especially on such a large scale project.

Discussion about the first draft of

This page is to discuss the first-draft of W3C’s <picture>-element. Discussed and voted changes will be submitted to Wiki = draft.

 

1) Wouldn’t we drop alt attribute from picture to make use of the full alternative content inside the <picture>-wrapper? Thought we discussed this in several threads already… I personally think this makes sense.

2) Do we really need <picture> as element-name? WHATWG mailing list and its contributors seem to have spoken that img could also work…? If it would, it would be a much smarter solution.

3) Templating ways are still missing. We never discussed this to the end…

4) Does it really make sense to provide srcset along with media attribute? I think it is much better to either use srcset and let the UA detect which one to choose or provide media and fixed source to serve as the developer wants to.

 

First Draft of Picture Element Proposal published by Responsive Images Community Group

On 2012-07-02 the Responsive Images Community Group published the first draft of the following specification:

Participants contribute material to this specification under the W3C Community Contributor License Agreement (CLA).

If you have any questions, please contact the group on their public list: public-respimg@w3.org. Learn more about the Responsive Images Community Group.

The Picturefill named Div

So I was messing with my own site when this spark started (also the same time Scott was updating the repos) and I’d like to get some feedback from outside entities. To give you an idea of what I’m talking about let me show you this little snippet (pasted below) and mind you this is just for the stupid little social icons in my footer. I’ve implemented the most recent commits from Picturefill that I’d like to personally go ahead and coin as “Divfill.”

[side note : This Divfill artist formerly known as Picturefill now appends an img element within div[data-picture]. As you hopefully will see this markup pattern can get unruly very quickly if used on a larger scale.]

I've also created a new branch with my own fork of Picturefill where I'm putting together a real world example using this technique of Scott's on a larger scale –with a Flickr–like layout. I hope we can use this live example and build upon it as a way to identify verboseness and at the same time indicate what's working. I've done this only because a real world example is crucial to understand what we really need. This isn't to blow the wind out of the Divfill sail. The two example images in use are just not cutting it. As they say, the proof is in the puddin' so here comes the spoon.

Markup using div polyfill

The following is the snippet I used within my footer. I also set my fallbacks for Retina


<article id="footer-socials">
<h3>Follow Along</h3>
<ul class="socials-listing">
<li class="twitter">
<a href="https://twitter.com">
<div data-picture data-alt="">
<div data-src="img/twitterBird.png" data-media="screen"></div>
<div data-src="img/twitterBird@2x.png" data-media="(-webkit-min-device-pixel-ratio: 2),(min-device-pixel-ratio: 2)"></div>
<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->
<noscript><img src="img/twitterBird.png" alt=""></noscript>
</div>
</a>
</li> 

<li class="dribbble">
<a href="http://dribbble.com">
<div data-picture data-alt="Social Follow Buttons">
<div data-src="img/dribbbleLogo.png" data-media="screen"></div>
<div data-src="img/dribbbleLogo@2x.png" data-media="(-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2)"></div>
<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->
<noscript><img src="img/dribbbleLogo.png" alt=""></noscript>
</div>
</a>
</li> 

<li class="facebook">
<a href="http://www.facebook.com">
<div data-picture data-alt="Social Follow Buttons">
<div data-src="img/facebookLike.png" data-media="screen"></div>
<div data-src="img/facebookLike@2x.png" data-media="(-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2)"></div>
<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->
<noscript><img src="img/facebookLike.png" alt=""></noscript>
</div>
</a>
</li> 

<li class="github">
<a href="https://github.com">
<div data-picture data-alt="Social Follow Buttons">
<div data-src="img/githubOctocat.png" data-media="screen"></div>
<div data-src="img/githubOctocat@2x.png" data-media="(-webkit-min-device-pixel-ratio: 2), (min-device-pixel-ratio: 2)"></div>
<!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->
<noscript><img src="img/githubOctocat.png" alt=""></noscript>>
</div>
</a>
</li>
</ul>
</article>