Google HTML/CSS Style Guide – Omit Optional Tags
google.github.io
google.github.io
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.
HTML 4/4.1 was kind of messy, and could have rendering issues. So going with an (x)HTML validator was a common thing, as well as a marketable value proposal to clients.
HTML 5 had much "saner" implementations, so validators fell by the wayside as they weren't as necessary for compatibility.
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)
And the overhead of tracking which tags are optional in which circumstances is not particularly small. Consider that the extra complexity could impede more optimizations in the future, especially now that your markup requires a more complex parser than it could have needed.
According to this study [1], 70% of web traffic is video streaming. Only 8% are web browsing (which might include images, because they are not mentioned anywhere else - didn't find any info on that).
This is not going to make any difference.
Sure, a lot of the traffic is streamed data rather than HTML, but 30% of close to a zetabyte of data in a single day (for the internet as a whole) is still hundreds of petabytes that can be made drastically smaller. When the numbers are that large, even optimizing for something as "insignificant" as 0.01% of the traffic means 10s or even 100s of terabytes not pumped through the network every day.
You would have a better day to let webmasters know to use gzip if they aren't.
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.
By the way, Jade is in the process of being renamed to Pug because of a naming conflict with someone who holds the rights to the Jade name in another context.
Do one thing and do it well, pretty much.
EDIT: editting since I can't reply to child post.
The thing is, if jade does it well on its own, then all the other tools won't profit from it. I believe jade should focus on outputting easy to understand, well-indented HTML.
When debugging HTML problems (missing attributes or whatnot) in development, I always disable any kind of minifiers. If jade implements a minified output, it would need to be optional, further increasing complexity.
If minification is a build step, I can just disable that step. Easy peasy.
Edit:
Worrying about the fact that Jade/Pug optimizations won't benefit others completely misses the point. Any improvements to its parser wont help anyone else either. The question is how to make the best tool for the job.
Perhaps the inefficiencies of outputting sub-optimal HTML don't matter much in reality. But if optimal html output was easy to do we would expect it to be done, right? So the only question at all worth considering is how difficult it is to achieve optimal HTML output.
My gut tells me that better output can't be that much harder, but I have never looked at the code at all so I may be dead wrong.
Whether that is really important is another question; probably in the big scheme of things it's not worth worrying about. But I wouldn't dismiss it without knowing for sure that the costs in complexity to Pug are actually significant. That would require someone who knows the codebase to comment.
> 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.
<h3><a style="display:none" href="http://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwi36oSzi5fPAhWBh34KHQO2A0YYABAF&ohost=www.google.com&cid=CAASJORo9LOCMjoibKPv7gF6cak7OxiE3TtM_tpkLykYWNps5wdfUw&sig=AOD64_3sHUU366i6dStUuQ_sGYCNCCiv9A&q=&ved=0ahUKEwiswYGzi5fPAhVSVWMKHYoQDjQQ0QwIJQ&adurl=" id="s0p2c0"></a><a href="https://www.capitalone.com/credit-cards/compare/?external_id=WWW_VI194_ZZZ_ONL-SE_ZZZGO_T_SEM2_ZZZZ_c_Zg_" id="vs0p2c0" onmousedown="return google.arwt(this)" data-preconnect-urls="http://www.capitalone.com/,http://5138.xg4ken.com/" jsl="$t t-zxXzjt1d4B0;$x 0;" class="r-ifxiYWNp1hrU">Capital One® Card Offers - Apply for Credit Card Offers Now</a></h3>
<div class="ads-visurl">
<span class="_mB">Ad</span><cite class="_WGk">www.capitalone.com/ApplyFor<b>Card</b>Offers</cite>
<g-bubble class="action-menu ab_ctl r-iS1b0Exw3vQ8" jsl="$t t-R7dwiTmE0C4;$x 0;">
<a href="javascript:void(0)" data-theme="0" data-width="230" class="g-bbll" aria-haspopup="true" role="button" jsaction="r.saTe4DDW138" data-rtid="iS1b0Exw3vQ8" jsl="$x 1;" data-ved="0ahUKEwiswYGzi5fPAhVSVWMKHYoQDjQQJwgm"><span class="mn-dwn-arw"></span></a>
<div class="g-bblc" data-ved="0ahUKEwiswYGzi5fPAhVSVWMKHYoQDjQQKAgn">
<div class="_lBb">
<div>This ad is based on your current search terms.</div>
<div class="_zFc r-ivNjifPqiifI" jsl="$t t-h6cwAtrxkFI$t-wWNthJIwnKo;$x 0;">Visit Google’s <a href="javascript:void();" jsaction="r.8Na6VOGeTa8" data-rtid="ivNjifPqiifI" jsl="$x 7;" data-ved="0ahUKEwiswYGzi5fPAhVSVWMKHYoQDjQQKQgo">Why This Ad page</a> to learn more or opt out.</div>
</div>
</div>
</g-bubble>
</div>
<div class="ellip ads-creative">Find Great Rates & Rewards—Apply.</div>
<div class="ellip">Autopay · Online Banking · Account Alerts · Travel Benefits · Security Alerts</div>
<div class="ellip">Services: Apple Pay™, Chip Technology, Second Look®, Image Card℠, Wallet App</div>
<ul class="_MEc">
<li><a style="display:none" href="http://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwi36oSzi5fPAhWBh34KHQO2A0YYABAG&ohost=www.google.com&cid=CAASJORo9LOCMjoibKPv7gF6cak7OxiE3TtM_tpkLykYWNps5wdfUw&sig=AOD64_0_5WQ5HIxnRdQEOpUEmdSkkiWV4w&ctype=4&q=&ved=0ahUKEwiswYGzi5fPAhVSVWMKHYoQDjQQpigILCgA&adurl=" id="ads-0-0-2-1-0"></a><a href="https://findmycard.capitalone.com/?external_id=%7B_externalid%7D" id="vads-0-0-2-1-0" onmousedown="return google.arwt(this)">Find the Right Card</a></li>
<li><a style="display:none" href="http://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwi36oSzi5fPAhWBh34KHQO2A0YYABAH&ohost=www.google.com&cid=CAASJORo9LOCMjoibKPv7gF6cak7OxiE3TtM_tpkLykYWNps5wdfUw&sig=AOD64_2iwTNF-VPyK96RTweJ4TAggXM4pw&ctype=4&q=&ved=0ahUKEwiswYGzi5fPAhVSVWMKHYoQDjQQpigILSgB&adurl=" id="ads-0-0-2-1-1"></a><a href="http://www.capitalone.com/credit-cards/compare/?filter=nofee&external_id=%7B_externalid%7D" id="vads-0-0-2-1-1" onmousedown="return google.arwt(this)">Cards with $0 AMF</a></li>
<li><a style="display:none" href="http://www.googleadservices.com/pagead/aclk?sa=L&ai=DChcSEwi36oSzi5fPAhWBh34KHQO2A0YYABAI&ohost=www.google.com&cid=CAASJORo9LOCMjoibKPv7gF6cak7OxiE3TtM_tpkLykYWNps5wdfUw&sig=AOD64_1AOh7CWEmBWXjNLs4Oondpyt-JAg&ctype=4&q=&ved=0ahUKEwiswYGzi5fPAhVSVWMKHYoQDjQQpigILigC&adurl=" id="ads-0-0-2-1-2"></a><a href="http://www.capitalone.com/credit-cards/compare/?filter=popular&external_id=%7B_externalid%7D" id="vads-0-0-2-1-2" onmousedown="return google.arwt(this)">See Popular Cards</a></li>
</ul>shrugs should just let minifiers do the job.
Still, I agree that both types of optimization / minification should be done by the tooling layer.
[1] https://developers.google.com/closure/templates/docs/concept...
A lot of it is URLs, and of course you have to have full URLs on an ad, you can't use relative.
As for the number of elements, there's quite a few divs but there's also more elements to an ad than people realize due to the built in reporting interface.
Sure a simple banner ad might be able to get away with only two HTML elements (an anchor tag and an image tag), but that image will end up being a lot more data than a text ad with as many elements as this one.
Thats about 300 digits from an alphabet of 0-9a-zA-Z which my computer says allows for "NaN" unique combinations. They could shorten that by 95% percent and still give every atom a unique id.
... and thats just one URL. There are 4 or five more. For three lines of linked text.
<!-- Not recommended -->
<!DOCTYPE html>
<html>
<head>
<title>Spending money, spending bytes</title>
</head>
<body>
<p>Sic.</p>
</body>
</html>
<!-- Recommended -->
<!DOCTYPE html>
<title>Saving money, saving bytes</title>
<p>Qed.
Does the <head> tag really not matter anymore?There is not really any ambiguity that the head tag solves ever. Script tags don't act differently in or out of the head tag, and things like <title> are always going to do the same thing, so having the <head> block is at best a "comment" to the user that these elements are "head related".
A <script src="…" defer> always runs with a body, which is nice in any case since it keeps scripts together, lets the browser start loading every script right away, and is explicit about which ones need to run before the body. Sadly, defer is only allowed for script elements with a src attribute.
<html>
<body></body>
<head><script>alert(document.body);</script></head>
</html>
works fine. It's not a head vs. body distinction, it's just that the parser is stopped during inline scripts, and doing e.g. getElementById won't work if the script is declared after you.This is why window.onload and then jQuery's document.ready, and later, putting the script at the end of your file, is a best practice.
The parser creates an empty head element when it sees the <body> start tag, the second <head> start tag is ignored, and the <script> is treated as part of the body element. Try changing the body of the <script> tag to this:
alert(document.currentScript.parentNode);
It alerts "[object HTMLBodyElement]".The behavior is specced out here, if you're curious: https://www.w3.org/TR/html5/syntax.html#parsing-main-afterbo...
Think of <HTML>, <head> and <body> as implied rather than missing.
An example of a tag that almost everyone omits is <tbody>. A <tr> can't exist directly under <table> (per the DTD), so you're explicitly opening a <tbody> with your first <tr> and closing it with your </table>. If you look at the DOM in the browser, the <tbody> will be there.
Typically, you have one table header (thead) and one table body. In print, if the table spans multiple pages, you would want the header to re-appear on each page.
To see Google recommend this while they're simultaneously pushing Structured Data seems odd to me. Maybe they want everyone to do it with JSON-LD instead; who knows.
Sorry, but I'm going to keep using semantic tags that make the structure of my content obvious. P tags should not be hanging out in the middle of nowhere.
Do screen readers operate directly on HTML now?
Because presumably they look at the DOM. And the resulting DOM is identical, whether or not you close your <p> and <li> tags explicitly, or include your own <head>, <html> and <body> tags, or whatever.
Try it.
And this mode on VoiceOver up until 10 years ago was the default.
In the Windows world, yes, you're totally right.
Although I like to make <body> explicit to avoid ambiguity in case of <script> tags.
I've always been of the school of thought that it's a bad practice to depend on non-obvious behaviors that, when taken in the context of so many other rules that are explicitly defined, seem like a bug that's been codified into a de-facto rule.
Granted, <p> elements are special snowflakes in the specification (not seen as precisely a block element — because it's more limited in allowed content, a phrasing element, an inline element, etc.), but most online docs refer to it as a block level element, and in block level elements, you don't omit the closing tag.
Say what you will about XHTML (such things, I'll add, I'd likely join you in saying) but at least it had one thing going for it: a well-formed document was easy to test for. Note, I didn't say valid, I said well-formed. For that reason, I still write HTML as well-formed XML for easy linting, and then a tidy step later to turn it into plain-vanilla HTML (though, generally speaking, that last step isn't necessary).
Such a mess nowadays - and it's not just `<p>`, similar special snowflake rules exist for `<a>` and `<button>` too, and indeed lots of elements have special quirks that make composability a pain.
However, what does this really accomplish? Does it really save that much space and bandwidth? GZIP compresses text extremely well, so I don't see the usefulness in most cases. Sure, for really slow networks, e.g. in developing countries, it might matter, but the people that this guideline are targeting are likely not going to worry about that. Maybe at Google scale it makes a difference.
Beyond that, it really feels weird to omit the html tag and the head tags and I'd like to see how much more readable this optional tag omission is when you're dealing with a complex page with many meta tags and a ton of body content.
#thirdworldproblems, eh? There are more third-worlders than there are visually impaired people. Do you also disregard the blind?
I would think on Google scale saving a byte is like couple hundred dollars or some other non-trivial amount (but at same google scale this is pennies).
Then again, if Google homepage is 5 bytes less, gigabytes will be saved delaying heat death of the universe or something… :)
Browsers accepting tag soup is just a manifestation of the Robustness Principle [1]:
"Be conservative in what you send, be liberal in what you accept"
(Also, I'll point out that HTML allows the parser to abort at any parse error it defines, the first time it hits that parse error. So you can implement a relatively strict HTML parser that rejects content and have it comply with the spec.)
I wouldn't expect huge perf increases, but there are a few minor non-local effects such as self-closing tags that imply more branches than strictly necessary. It's not going to add up to much of anything, that's for sure. A simpler spec might, however, leave more complexity-budget for clever optimizations, but that's pretty speculative. The kind of thing I'm thinking about here is that when the language is fairly restrictive, you can consider using SIMD operations to match content cleverly; e.g. you might find the closing quote of an attribute four-chars at a time. Those kind of tricks require interplay decoding and parsing and are typically way to complicated in all but the simplest of cases.
In any case, this is drifting off topic: perf is not a primary reason to aim for simplicity, it's just a possible windfall.
DTD validation? As far as I'm aware, it would only be keeping it at a spec level—no implementation aside from validators ever implemented it. There's nothing stopping a browser from noting any validation error, though (and note they wouldn't just happen at parse time—they could happen following any DOM modification).
You say the HTML tag has no meaning, but it has the advantage of being explicit instead of implicit, as well as universal.
There are situations where implicit is better, because the explicit way feels like a big waste of time and demotivates developers.
There is also a lot of value in conventions, as all the efforts around coding standard and linting tools show. It forces different people to work more similarly, using an established way to do things instead of their own quirks, facilitating collaboration and sometimes educating them about the features and caveats of whatever they're using.
I've never been annoyed writing <html>, <head>, which happens a handful of times in the lifetime of a project that I'll spend thousand of hours on.
Again, I don't think any of this is relevant here, as those optional tags would be cleaned up at build or rendering time, and reinserted by the browser / parser. This seems like an awful lot of computation to save a few bytes though, but maybe processing power is that cheap nowadays.
If you consider how the parser for HTML5 actually works many of the closing tags you would encounter don't actually add any value unless you have some trailing text that should be attached to the parent node.
FWIW, there's also some trees which are impossible to serialise in HTML-without-parse-errors which I don't expect to ever round-trip, though all such trees also fail to match the schema. A trivial example of this is `<a><table><a>`, which ends up with an a element as a child of an a element (and is, far as I'm aware, the only way except for scripting to create such a tree).
Besides, isn't this "visual redundancy" (not to be confused with semantic redundancy) is what compression is supposed to solve, and has been solving since, effectively forever? So that we can code to reduce our (and the 'view source'-reader's) cognitive load, and let gzip or brotli or whatever new scheme work its compressive magic before it squirts our payload across a newfangled binary HTTP/2 protocol?
Both the optional closing tags for P and the optional opening tags for stuff like HTML, BODY, TBODY, etc. are present in the HTML 4.0 DTD too. (A TR element cannot go in a TABLE element, there is an implicit TBODY.) And SGML, HTML, and optional tags go back to before XML existed.
Code is read many more times than it's written. Removing unnecessary noise makes it easier to read.
One thing I've noticed is that bing webmaster tools will report "The title is missing in the head section of the page" when there is a title, but no <head>. Maybe bing can't properly crawl pages without a <head>. Another service I've used had the same problem, but can't remember which.
So it might be worth being careful with omitting <head> - and maybe other tags, I'm reconsidering whether it's a good idea.
Real documents don't look anything like this example. They have lots of meta tags and they have footers and they are expected to be read by a wider variety of user agents than "Google Chrome on Windows" and "Google Chrome on Android".[0]
Part of the problem is that we treat HTML as a canonical data format, when it should be a rendered data format. That's not to say that you shouldn't hand-write HTML for your small site[1], but if you're deploying more pages than can be managed by hand, then you should be A) use a data format for your content that is as rich as absolutely possible, and B) statically rendering that data down to a transmission format.
[0] I shudder to think what screen readers might think of this sort of markup. I mean, I make VR applications in the browser, but I still make sure the data is semantic. It's our duty to do so.
[1] AKA "the vast majority of cases". I whole-heartedly believe that new ventures--before it is known how large they will be--should be hand-written.
I alwats use this style, which imho is very handy, because of the tree structure and admittedly because I have a super cool macro in Vim that copies the characters from the line above, word by word so create rules that afect children of the rule above it requires just a few keystrokes:
#some-div { margin:1em 0; }
#some-div .inner { padding:5px 10px; }
#some-div .inner p { font-size:90%; }
This makes the structure of the declarations more obvious imho, and I tend to have a nicely organized series of structures like that that are logically grouped together.Obviously this applies more to components/widgets than the basic rules and layout.
If a declaration is long then I use newlines.. but even then I tend to group things together eg.
#some-div {
display:inline; margin: ...; padding: ...;
border-radius: ...; border-color: ...;
font-size:90%; text-align:center;
}
Basically within a css rule I'll group together the layout properties, the text properties, etc.Your second CSS example is no bueno. Don't put multiple properties on a single line. It might make sense to you to put display and margin and padding on a single line but it might not make sense to me. These should all be on separate lines, it's not worth "saving lines" to make your CSS harder to parse for someone who doesn't already know that you like to group X, Y and Z properties.
Well somewhat in between you could also put properties in alphabetical order as suggested in this Google Style Guide. That tend to work for me since "text" properties will be towards the end of the rule, and for me the layout properties like border, display, margin and padding is something I'd want to see first.
But where I prefer some freedom vs hard rules is that I'll also align properties to make the differences more obvious. In this YUI2 example, the second class is applied to a mobile version of the dialog, the common properties come first, that way the difference is obvious:
/* dialog body wrapper for extra css styling (.rtk-skin-dlg .yui-panel .bd .body) */
.rtk-skin-dlg .body { background:#fff; padding:10px; border-radius:3px; box-shadow:0 1px 3px rgba(0,0,0,0.2) inset; }
.rtk-mobl-dlg .body { background:#fff; padding:10px; }How is it harder to parse? Putting everything in separate lines make the CSS file 10 times longer, and it's more difficult to see groups of rules that fit together along with their common structure.
Nowadays unless you edit on a tablet your text editor probably handles 120 columns or more.
But I really can't see the argument for readability. When I navigate a stylesheet for a website I'm working on, I want to see the larger structure. I don't need to see clearly the properties within a single rule. I want to see from top down.
Still, this could be argued forever. Apples and bananas :) I guess it's the same discussion as space vs tabs, or 2 space vs 4 spaces.
Here's a better example from one project which used YUI2 (it's old, but I think it shows my point of view, that the dtk-skin-dlg structure is very obvious along with the hd/bd/ft structure YUI 2 uses and the styles applied to them, that's the structure I want to see readily when I work in a stylesheet without having to scroll to understand it's all connected together):
/* dialog body */
.dtk-skin-dlg .yui-panel { outline:none; }
.dtk-skin-dlg .yui-panel .hd { font:16px/1em Verdana, sans-serif; color:#ddd; padding:10px 10px 0; background:none; }
.dtk-skin-dlg .yui-panel .bd { padding:10px 10px 10px; background:none; font-size:12px; line-height:19px; color:#000; }
.dtk-skin-dlg .yui-panel .ft { padding:5px 10px 10px; background:none; font-size:12px; line-height:1.2em; color:#000; }
/* dialog footers, right aligned */
.dtk-skin-dlg .ft-right { clear:both; width:100%; padding:5px 0 0; text-align:right; }
/* left align buttons INSIDE ft-right */
.dtk-skin-dlg .ft-left { float:left; text-align:left; /*padding from ft-right*/ }
/* dialog body wrapper for extra css styling */
.dtk-skin-dlg .body { background:#fff; padding:10px; border-radius:3px; box-shadow:0 1px 3px rgba(0,0,0,0.2) inset; }
.dtk-mobl-dlg .body { background:#fff; padding:10px; }You block them together just like we do with code. Good code doesn't put multiple statements on a line, good CSS doesn't either. File length means nothing, if someone's looking for a specific class there are tools to do that, saving a few lines and making the CSS harder to read and edit isn't worth it.
The examples above are much more readable like this (margin added for illustration of grouping related properties):
.dtk-skin-dlg .yui-panel .hd {
font: 16px/1em Verdana, sans serif;
color: #ddd;
background: none;
padding: 10px 10px 0;
margin: auto;
}
Written that way, when someone finds that rule in the file they can easily parse the relevant property without having to scan a 200 character long line.Besides I like that it also gives me a better sense of how verbose some of the rules are and if some of the properties could be removed entirely. When the hierarchy of those rules is more apparent with the more compact style, I'm more likely to see unnecessary properties (which are inherited) and therefore trim up the code.
" Piece-wise copying of the line above the current one
:imap <C-L> @@@<ESC>hhkywjl?@@@<CR>P/@@@<CR>3sI mean if you are Google, yes that 1kb matters a ton. But they've already optimized to the point where minifying their HTML makes sense.
And you really think about minification of html, js, or css to save some bytes?
It's not so much about "if you're google" but "if we all do this": a 0.001% reduction in global byte transfers would constitute a massive saving despite looking like a tiny number.
http://www.paulirish.com/2010/the-protocol-relative-url/
This page outlines the original argument, as well as the updated reasoning that you suggest: always use HTTPS if it is available, even if requesting from a page served over HTTP.
namely, the always beloved <noscript> tag https://developer.mozilla.org/en/docs/Web/HTML/Element/noscr...
which is a flow content element in the body section
but if used in the <head> it might include links, style and meta-tags and then it should not be treated as content element.
as the <head> element therefore changes the behavior of its child-elements, does this make it non optional?
p.s.: i think DOMParser.parseFromString() in Chrome gets this <noscript> behaviour wrong in some cases (closes the <head>-section as it treats the <noscript>-tag as content-element, even though it is in the <head> with just links & style children, so it shoudn't close the <head>...)
in the head with scripting disabled (no text, only link, style, meta)
in the head, with scripting enabled (can include text (like whitespaces) but parsed elements must result in link,style,meta DOM only)
in the body with scripting disabled (text, but no other noscript)
in the body with scripting enabled (text, but no other noscript and script tags)
so basically
<html><noscript><link href="e.css"></noscript><title>hi</title><h1>ho</h1>
would be find, as the <head> would close just before the <h1> (in scripting enabled and disabled case)but:
<html><noscript> <link href="e.css"></noscript><title>hi</title><h1>ho</h1>
would close the <head> in a scripting disabled case just before the <noscript>-tagand closes the <head> just before the <h1> in a scripting enabled case.
this would explain the DOMParser.parseFromString() behaviour, as it's a scripting disabled case....
In Chrome Canary 55.0.2866.0 the noscript element contains a text node and a link element. This matches the spec as far as I can tell; whitespace is allowed in noscript in head.
In this case we have the weight of Google that says "oh it's in the spec so we can do it".
In other case we have a standard like E4X, that everyone happily not implemented (Chrome) or removed (Firefox).
They could as well say "If we don't like it we will not do it, if we like it we will do it", that would be exactly the same.
Welcome to HTML5: a document that comes out of the work of tens of thousands of people across decades of historically-encumbered practices. It's done remarkably well, and if you actually read the spec, is way more sensible than you would think that development track would give us.
Emit all optional parentheses in expressions, unnecessary "break;" statements at the end of a switch, the type specifier keyword "int" when "unsigned" is already present in the declaration and other such fluff.
I've done plenty of web scraping in which it was helpful to look for the <body> element.
Leaving out optional tags makes sense. These days, at least with web-apps, It's not like we are writing a <head> for every page. It's just a partial you rarely ever interact with anyway. Either leave them in or take them out. The only negative I could see is that some people may not know what's optional–think you're a dummy–and put them back in. Probably best to just follow the conventions of whatever framework you use. Save your fighting energy for trailing commas in JSON! :)
https://html.spec.whatwg.org/multipage/syntax.html#the-docty...
In XML, it's required uppercase. Unlike HTML being lax on tag structure, there is no reason to advise DOCTYPE to be lowercase. It's not "better".
Just curious, how often are practices like these where the company you work for gives you a detailed overview of all the coding conventions you should follow? Is this absolutely expected to be followed strictly when you start any job as a developer? Is this something a lot of workplaces follow or mainly the big boys(Google, Facebook, Twitter, etc). If you miss maybe one or two coding conventions in a huge commit for instance, do you hear about it or does the reviewer just fix it and you can see what's changed?
Just curious as I'm still new to transitioning into the workplace when it comes to source control. I work with one other developer (my boss) who wrote for more or less the entire system himself and there is no such document - I just have to observe the patterns used and follow suit.
[1]: This is my opinion. Anecdotally, places with style guides tend to have better engineering cultures.
[2]: Again, opinion. This tends to indicate a weak culture (dictatorial lead or a lack of awareness/ability when it comes to tools) and can produce a negative atmosphere (nit-picking isn't fun).
Are there public tools out there you can use prior to commits for this purpose or are they generally done in-house?
[1]: https://github.com/brigade/overcommit
[2]: E.g., flake8 for Python: https://pypi.python.org/pypi/flake8
[3]: E.g., gofmt for Go: https://golang.org/cmd/gofmt/
Like, when you start a new paragraph it doesn't become a new "subparagraph", it just ends the current one and starts a new one. I really don't think it's hard.
I do think omitting needless stuff creates more compact documents with less redundant boilerplate that distracts the eyes.
Omitting `<head></head>` saves 13 bytes, assuming gzip didn't help in the first place. The average page weighs thousands of bytes, according to https://www.sitepoint.com/average-page-weight-increased-anot...).
If your pages are like the average, you've already wasted too much time thinking about this. Go optimize your images, use less JS, and make 200 other size optimizations first. You'll probably never get around to this one.
I'd have assumed someone with Google's resources would have produced at least a linter, if not a fmt tool to enforce these rules. Have they not?
[1] https://google.github.io/styleguide/htmlcssguide.xml?showone...
How is adding a space after ":" any more consistent than having none? No space between property and value is more unique and searchable should you need to find something or do search/replace.
I wouldn't get too worried about crawlers and parsers.
if (x) { ... ... } someMethod()
Changed to :
if (x) { ... ... someMethod()
It's not as readable. Maybe as others have suggested, leave it to a compiler.
In the head tag, I intentionally load a small bootstrap javascript bundle (~50K) non-deferred. This bundle contains a subset of my CSS that styles all of the static tags the body below will first render with. This bootstrap bundle also starts an AJAX call for polyfills, if needed, and the main page script (which also contains the rest of my CSS.)
My goal is to have no unstyled tags in the body as it first renders and to kickoff loading the main body scripts ASAP before any other 3rd party scripts have a chance to get started loading.
HTML4, XHTML: Make sure to include all optional tags, because scannability.
Now: For (...) scannability purposes, consider omitting optional tags.
Use double ("") rather than single quotation marks ('') around attribute valuesIf its less code to type and send over the network then that's great. HTML 5 is not XML. Which is fine.
demo: http://jsbin.com/duqonahiyi/1/edit?html,console,output
https://github.com/google/styleguide/blob/gh-pages/htmlcssgu...
>Indent by 2 spaces at a time.
>Don’t use tabs or mix tabs and spaces for indentation.
Let the wars begin.
In reality in browsers, that coercion to an infoset never actually happens, and XPath is matched directly against the DOM, which leads to differences in edge-cases (notably, adjacent text nodes, which the DOM allows and the XML infoset does not).
Since this code follows the official HTML5 spec to the letter (optional means optional - a parser will do the same whether an optional thing is written our or left off), HTML5-compliant parsers just see "correct data" and convert it into the only DOM it can be turned into.
However, I am a big fan of the robustness principle: Be conservative in what you do, be liberal in what you accept from others.
So for me personally, the issue is clear-cut. I will keep my codebase as clean as possible/affordable, be it HTML or C++, not relying on quirks that have been introduced to tolerate faults of careless designers and programmers.
https://en.wikipedia.org/wiki/Standard_Generalized_Markup_La...
Technically I could put all my HTML into base64 encoded strings in javascript and then write them to the document, that doesn't mean that I should.
It's certainly something you should either do automatically or in a consistent style, not as an excuse to leave out random things if you feel like it.
I think the failure of XHTML shows that this was in fact not universally agreed. Seriously, when’s the last time you saw a page served as application/xhtml+xml?
Documents malformed this way cannot be parsed e.g. with PHP's DOM functions without significant headache.
If PHP's DOM functions don't work for it, then PHP's DOM functions aren't HTML5 spec compliant, and that should be filed as issues against PHP and fixed by its developers.