by kgtm · 10y ago · 0 comments
What happened to optimizing for mental overhead instead of file size? This simply should be a build step, part of your minification and concatenation dance, not having to consider all of these when trying to decide if I should close my <p> tag or not:
A p element's end tag may be omitted if the p element is immediately followed by an address, article, aside, blockquote, details, div, dl, fieldset, figcaption, figure, footer, form, h1, h2, h3, h4, h5, h6, header, hgroup, hr, main, menu, nav, ol, p, pre, section, table, or ul element, or if there is no more content in the parent element and the parent element is an HTML element that is not an a, audio, del, ins, map, noscript, or video element, or an autonomous custom element.
Silent errors include things like malformed tags and attributes, incorrect nesting structure (thus also messing up where CSS rules are applied), and unescaped left-angles and ampersands.
If I were inclined to follow Google's guidelines on omitting optional tags, it would be easy to write a stream filter that removed them [3].
But I prefer source templates to have all the explicit properly indented structure, so they're easier to validate and process with XML tools (and by eye), and unintentional mistakes don't sneak through as easily.
For the same reason, I also prefer not to write minified JavaScript source code: that should be done by post-processors, no humans. ;)
[1] https://genshi.edgewall.org/
[2] https://genshi.edgewall.org/wiki/ApiDocs/genshi.output
[3] https://genshi.edgewall.org/wiki/Documentation/streams.html#...
If on the other hand you are not closing tags that autoclose, how can your editor tell you? There is no way to know it's not intended.
But mostly I meant that you don't have to close the autoclosing tags.
[1] https://www.w3.org/TR/html5/syntax.html#obsolete-permitted-d... [2] https://www.w3.org/TR/html5/infrastructure.html#namespaces
You're right lets not bother ourselves with this small things, cause === and == do the exact same comparison in Javascript and all browsers are exact replicates when implementing html, css and javascript.
Beyond all the sarcasm, in reality, web programming is a hassle. But other programming languages and markups have their quirks as well. I'm glad you found a solution, but it doesn't mean we shouldn't look at the fine details of a specification.
I also don't bother remembering how == works. I use === everywhere. The reason is the same - lower cognitive overhead.
>all browsers are exact replicates when implementing html, css and javascript
The browsers I care about all parse XML correctly.
>I'm glad you found a solution, but it doesn't mean we shouldn't look at the fine details of a specification.
I'm only talking about myself, yes. I only make websites for my personal projects. I'm certainly not a web dev by profession or even by hobby.
The real mental overhead is incurred when reasoning about the tag following the p, which could be anything. "Hmmm, I have a nav tag coming after this p tag. Does that implicitly close it?"
Although if you had a good autoindenter, you could catch any mistakes by how it was indented. "Oh, that nav tag is on the same indentation level as the p tag, I guess it does implicitly close it."
This is a great point, but when I think of build steps, I think of something like minifying which comes with a performance gain.
I'm not sure I see what the obvious gain to omitting optional tags in the way Google suggests is.
Edit: To clarify, I'm wondering if there's some performance gain by the browser not having to parse the implicit optional tags.
This is minification, isn't it?
Possibly faster parsing, because the parser has less HTML so go through. (also probably not valid, because I'd be pretty sure that reading a string from memory is not the bottleneck in parsing, compared to logic, memory allocations, etc).
It could make a difference for Googles server infrastructure though.
If they have to download a tiny bit less, and save a tiny bit on CPU cycles and memory for each page, , it might still lead to considerably savings.
The motivation behind this style is not browser parsing perf - it's network perf. The smaller your HTTP response, the fewer packets (and round trips) required to transmit it.
(which, IIRC, was the original rationale behind that style guide rule)
I'm still bitter that HTML/XML works based off of explicit closing tags (where you can mistakenly close the wrong tag) instead of something like braces.
Alternatively, don't use HTML at all. Use pug (formerly "jade") or something and now you're free from all those inconvenient angle brackets.
Many React/Webpack flows do something like this (minify or use a barebones template HTML).
Yes, sometimes it is better to make developers think about when and where certain things are required.
Frankly I'm amazed the HTML way of verbose writing still stands after all these years in a fast paced industry.
> This doesn't apply if you are doing weird stuff in a non-block-ish element, or a media element, or a custom element.
is the easier way to think about it usually
<p>
It naturally acts as a clean way to segment
paragraphs of text
<p>
And most of the tag-closing rules are roughly
matched with the rules of using p tags altogether.
<p>
e.g. you can't have a div within a paragraph, so
closing or not closing, divs can only come after
paragraphs!.I just took a sample page out of here which has bunch of p tags open and closed, gzipped the original and the one with </p> stripped, difference was 39 bytes.