diveintomark / diveintohtml5

Dive Into HTML5 online book
https://diveintohtml5.info/
Other
776 stars 188 forks source link

Type is not required in a link tag #21

Closed GeorgeLangley closed 11 years ago

GeorgeLangley commented 12 years ago

http://diveintohtml5.info/semantics.html#link

says that a link with rel=stylesheet can drop the type but that type is required for rel=alternate. However, the official specs:

http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html

list it as optional and that a device should not rely on the type specified in the link as being accurate.

http://www.w3schools.com/tags/tag_link.asp

lists it as optional and

http://validator.w3.org/

validates a link with and without a type as valid. Am thinking that section needs a rewrite or clarification on why one should include a type if it is going to be ignored by a device anyways. Is it a fallback for non-HTML5 devices?

jonathantneal commented 12 years ago

http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#rel-alternate

The alternate keyword may be used with link, a, and area elements. The meaning of this keyword depends on the values of the other attributes. ... The alternate keyword is used with the type attribute set to the value application/rss+xml or the value application/atom+xml

And the example provided:

<link rel="alternate" type="application/atom+xml" href="data.xml">

From this documentation, where do you read the type on rel="alternate" as optional?

In DiveIntoHTML5, the context is:

This link relation is also quite common. <link rel="alternate">, combined with either the RSS or Atom media type in the type attribute, enables something called “feed autodiscovery.” ... Unlike with rel="stylesheet", the type attribute matters here. Don’t drop it!

GeorgeLangley commented 12 years ago

Hi Jonathan; thanks for the reply and for your work on this resource. I found the DiveIntoHTML5 line confusing and it could use some clarification. From section 4.12.2 on whatwg.org link above:

_The type attribute, _if present, gives the MIME type of the linked resource. It is purely advisory. The value must be a valid MIME type. User agents must not consider the type attribute authoritative — upon fetching the resource, user agents must not use metadata included in the link to the resource to determine its type.

So that is where I got that type is optional. In fact, devices are instructed NOT to use it verbatim. The whatwg blog:

http://blog.whatwg.org/feed-autodiscovery

also confirms that type is optional:

It also means that you do not need to specify the type attribute to have the link recognised as a syndication feed and browsers can still show it in the subscription list.

However, the type is required if you want to set one of your links as the DEFAULT feed for that page. The whatwg.org page, section 4.12.5.1 explains:

The first link, a, or area element in the document (in tree order) with the alternate keyword used with the type attribute set to the value application/rss+xml or the value application/atom+xml must be treated as the default syndication feed for the purposes of feed autodiscovery.

IOW, you could have three rel="alternate" links on your page, but set the second one as the default feed by specifying its type and not setting a type for the first link:

<link rel="alternate" href="data1.xml">
<link rel="alternate" type="application/atom+xml" href="data2.xml">
<link rel="alternate" type="application/atom+xml" href="data3.xml">

All three links will be discovered as feeds, thanks to feed autodiscovery, but the second link is the first one to meet the requirements to be considered the default feed for that page.

I would propose replacing the paragraph with the following:

This link relation is also quite common. enables something called “feed autodiscovery.” It allows syndicated feed readers (like Google Reader) to discover that a site has a news feed of the latest articles. Some browsers also support feed autodiscovery by displaying a special icon next to the URL. A type is not required (and, in fact, is ignored by the reader). However, if you have multiple rel="alternate" links on your page and want to specify which one should be considered the default for that page, simply add a type (type="application/atom+xml" or type="application/rss+xml") to that link and remove it from the others. The first link found (in tree order) that specifies a type will be considered the default feed for that page.

Thanks again!

jonathantneal commented 11 years ago

I understand your points, and you're right in a computer way. Indeed, "type" is optional, but like many optional features, if you want the desired effect, then using it is required. Also, the additions needed to illustrate such a minute detail would take away from the easy, breezy, beautiful style of the chapter.

If you're not satisfied with my reasoning, I am absolutely open to you commenting again or reopening the issue.