Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"As a side note, it looks like Twitter omits the HEAD tag for performance reasons"

Yeah, right.

HTML is supposed to be <html><head>head stuff</head><body>body stuff</body></html>. But in practice you see multiple HEAD sections, missing HEAD sections, multiple BODY sections, missing BODY sections, and even multiple HTML sections. If you omit all those tags, it still works, mostly.



It's an absolute necessity that they shave 13 bytes off the packet size... to make room for more advertisements. Their page size is 90KB for me, which isn't great nor terrible, but violating standards "just because" feels unnecessary.


Omitting the <head> tag doesn’t violate any standard. It’s valid HTML.


    The title tag SHOULD occur in the head of a document[1]

    The <title> element is always used within a page's <head> block.[2]
Just because browsers are compatible[3] doesn't mean what you're doing is right. Twitter does set a title tag and thus that tag should be within a head block. They are leaning on browser compatibility mode to cover the fact that they aren't adhering to standards.

1. https://www.w3.org/Provider/Style/TITLE.html

2. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ti...

3. "HTML5-compliant browsers automatically create a <head> element if its tags are omitted in the markup. This auto-creation is not guaranteed in ancient browsers." https://developer.mozilla.org/en-US/docs/Web/HTML/Element/he...


> Twitter does set a title tag and thus that tag should be within a head block.

It is in a <head> element. You don’t understand how HTML is parsed. The opening and closing tags for the <head> element are optional. That doesn’t mean the element isn’t there, it means that the element is always there.

> They are leaning on browser compatibility mode to cover the fact that they aren't adhering to standards.

They aren’t. See this comment I made and go ahead and paste that HTML into a validator:

https://news.ycombinator.com/item?id=30475015

There is no error handling taking place, there is no browser compatibility mode involved. This is correct HTML that adheres to the standard being parsed normally.

> [1], [2], [3]

Why are you quoting a style guide written in 1992 and two unofficial sources when you could just as easily have referred to the actual HTML specification?

> § 13.1.2.4 Optional tags

> Certain tags can be omitted.

> Note: Omitting an element's start tag in the situations described below does not mean the element is not present; it is implied, but it is still there. For example, an HTML document always has a root html element, even if the string <html> doesn't appear anywhere in the markup.

https://html.spec.whatwg.org/multipage/syntax.html#syntax-ta...

The HTML specification literally gives this as an example of a valid document:

    <!DOCTYPE HTML>
    <title>Hello</title>
    <p>Welcome to this example.</p>
There are a great many ways in which people write broken HTML and the browser repairs things. This is not one of them. Omitting the opening and closing tags for the <head> element is perfectly correct HTML that adheres to the standard.


> HTML is supposed to be <html><head>head stuff</head><body>body stuff</body></html>.

It’s not. Every single part of what you quoted is optional, and you didn’t include the parts that are actually required.

This is a complete, valid, correct HTML document:

    <!DOCTYPE html>
    <title>…</title>
    …
> But in practice you see […] missing HEAD sections […] missing BODY sections

You never see this, ever. It’s not possible to have an HTML document without a <head> or <body> element. The document I listed above has one <head> element and one <body> element. Both the opening and closing tags for these elements are optional. When an HTML parser parses that document, it will construct a DOM with those elements in it.

> If you omit all those tags, it still works, mostly.

Omitting these tags works completely. This is valid HTML that follows the HTML specification correctly without any need for error handling. All browsers follow these parsing rules without any problems.


You beat me to the punch, but at least I can support with a link to the spec: https://html.spec.whatwg.org/dev/semantics.html




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: