When I was putting together my post on responsive HTML5 video last week, it led me to investigate the
media attribute of the
source element a bit further.
First of all I’ll talk about what it does, albeit briefly since I spoke about it and showed how it can be used in the post linked to above.
Both of the HTML5 specifications describe the
media attribute as:
The media attribute gives the intended media type of the media resource, to help the user agent determine if this media resource is useful to the user before fetching it. Its value must be a valid media query.
This bascially means that you can provide a media query for a media source and if the browser decides that the condition has been met, then that source is the one that will be used when serving the content to the user.
As mentioned in my responsive video post, this is useful when you want to provide different content when the user is likely to be on a mobile device, potentially with less bandwidth available.
But this useful attribute may be disappearing from the HTML5 specification.
I must admit that I have no idea. The one mention where it might be disappearing is in a WHATWG mailing list posting by Philip Jägenstedt of Opera, dated the . No reason is given, just as the posting itself mentions that no reason can be found as to why it was added to the specification in the first place.
Of course it might also be a bit daft to assume that because it is mentioned in one mailing list that the attribute will disappear altogether. It equally may not.
Philip point out in his mail that he thinks that the
media attribute is “mostly useless” and that he has “never heard of it actually being used”. Judging by what some people who have read my responsive video post, it hasn’t been used much because people weren’t aware of its existence! Philip does go on to say that “the correct way to handle different screen sizes and bandwidth constraints is adaptive streaming” about which he is totally correct.
It’s all we have
But we don’t have that capability yet. Whatever eventually comes out of the adaptive images discussion will undoubtedly be extended to be used for adaptive video and audio, but that also hasn’t arrived yet. But we do currently have the
media attribute and so we should be encouraging people to use that for now.
With work already having begun on HTML.next and with minimal changes left to be made to the HTML5 specification, I think we should leave the
media attribute in the specification for now, as it can always be removed in HTML.next when an improved alternative exists.