Google HTML/CSS style guide suggests omitting head and body tags
google.github.io
google.github.io
I'm pretty sure you could remove all the head and body tags from the entire internet and it would still make less of a performance impact than if every WordPress blog stopped using Google fonts.
<!-- Google Analytics -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r; i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g; m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
That's 455 bytes, even if you have an adblocker and don't load the external javascript. No amount of removing html, head, and body tags will overcome this.After I explained that they were getting incorrect information I was told "I know this isn't exactly ethical ..." yada yada. I fired that client.
But there's no reason to ignore literally free improvements just because there's bigger, not free improvements to be had as well.
---
>Are you referring to the group think that Google is full of evil hypocrites?
I'm confused, what are you trying to say?
Omit optional tags (optional).
And google.com used to do this, along with other ugly but valid byte-saving hacks, but as the page has gotten richer they've loosened up a bit.(Seems like a terrible idea to me - complex rules to follow for a really minimal saving...)
These days Im trying out pug instead, which is similar in a sense: more concise and readable at the expense of other people being certain of its correctness and myself remembering the syntax months later.
And every web developer references the spec when they have questions...don't they?
And for what - to save literally 10 bytes?
The savings from this won't be the slightest bit significant to them.
Eg. why can't the closing tag for title be omitted? Tags are not allowed inside it.
I guess it's because you should be able to type tags as the title, but having to think about stuff like that makes ommiting more of a hassle than it's worth to me.
And what if templates are used and put together? Then you suddenly need to know how every combination of templates is going to be in the future to avoid unintended side effects.
Saving a bit of data on HTML isn't my top priority, and why would it? Just by not using a bunch of css/js-libs/fonts I'm able to have a smaller footprint than 99 percent of all pages.
You're commented needed to modified for current times. ;-)
If this was truly the case, we wouldn't need things like Applitools to view our HTML documents in various browsers to scan for differences.
The example document in the HTML+ spec (1993) did not use them: https://www.w3.org/MarkUp/HTMLPlus/htmlplus_7.html
The HTML 2.0 spec gives this as its first example:
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<title>Parsing Example</title>
<p>Some text. <em>*wow*</em></p>Certainly by the point of HTML 2.0 (November 1995; the first non-draft spec for HTML) all three elements have start and end tags all optional.
The more general ability to omit start/end tags from given elements is a feature of SGML (October 1986), and HTML 2.0 to HTML 4.01 were defined as SGML applications (though approximately nothing ever used an SGML parser for HTML).
Note though that there are some conditions.
Sounds superstitious.
<html><head><title>foobar</title></head><body><p>Hi</body></html>
vs <title>foobar</title>
<p>Hi
Number two looks way easier. If you were to write code to parse #1 you would just need extra code to ignore the useless tags.Anyway, parsing HTML is a nightmare, and HTML documents are usually broken in the wild, and browsers still, amazingly, manage to render almost anything you throw at them. I'm sure they all already handle it.
Maybe you haven't considered it closely enough?
If you look at the specifications, there is a complex set of rules governing the conditions under which a tag may be omitted. These naturally complicate the syntax. Consistency is preferable because it typically results in a simpler syntax.
Consider the following language:
document ::= tags
tags ::= tag { tag }
tag ::= '(' symbol [ tags ] ')'
symbol ::= 'x' | 'y' | 'z' | 'w'
It encodes a document like the following: (x (y) (z) (y (w (x))))
(z (w (z) (y)))
i.e. a list of trees of tags named by symbols.Now, try to describe the language that's identical except that the closing bracket is optional if it belongs to a 'w' tag that precedes an 'x' tag. Try even to describe a language where they are not optional, but must be omitted. They'll both be more complex than the language I described above. Now imagine that there are about a hundred such exceptions, as in HTML. Chances are that rather than encoding them as syntax for the parser, you'll complicate the lexer to automagically insert the optional tags, fuzzying the boundary between the lexer and parser.
> Anyway, parsing HTML is a nightmare, and HTML documents are usually broken in the wild
Exactly because the syntax is needlessly complicated.
What is a machine supposed to do with the <html> tag? It's entirely useless and tells you nothing. At best it could be used to identify file type, but the doctype has long since replaced that usage and that still wouldn't justify any reason for the end tag.
Similarly for <head> and <body>. They don't really do anything. There's no machine-useful structure to be had from that.
For some of the optional end tags sure, that definitely helps make things easier for machines to understand. That's why XHTML exists. It's not really used, though, but if you really want easy to understand document structure for machines you wouldn't go anywhere close to HTML in the first place and instead use XHTML.
I thought it was referring to the <main> tag.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ma...
> This project (google/styleguide) links to the style guidelines we use for Google code. If you are modifying a project that originated at Google, you may be pointed to this page to see the style guides that apply to that project.
These are just Google's style guides for their own code. They're not saying you should do this in your own code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Google HTML/CSS Style Guide</title>
<link rel="stylesheet" href="javaguide.css">
<script src="include/styleguide.js"></script>
<link rel="shortcut icon" href="https://www.google.com/favicon.ico">
<script src="include/jsguide.js"></script>
</head>
<body onload="initStyleGuide();">
[...]
</body>
</html>Is there much savings omitting body and head tags?
This seems like excessive optimization where having them there sometimes because someone left them in, but omitted the next because someone else removed them seems like it could be confusing, a few brain cycles might be more valuable than the possible savings.
Granted I'm not Google so maybe there are some great savings to be had there, I'd like to know what they are.
Is it correct to put a title element outside of a head element?
"Permitted parents: A <head> element that contains no other <title> element."
"The <title> element is always used within a page's <head> block."
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ti...
Google's style guides aren't very good in general, including Python, which doesn't follow PEP8.
<!DOCTYPE html>
<title>title</title>
<style>body { color: #111; }</style>
<p>content
the title and style elements are both inside the head element.> Use UTF-8 (no BOM).
I was mystified the first time I read about "byte order mark" and I'm still confused. I mean, I know that if you want to waste space on 16-bit characters, it might make some very small amount of sense to have a byte-order mark, but for crying out loud, just standardize that order and live with it. We don't need more parts of text file that are interpretable, and cause both usability problems and security problems.
That's not to say that abolishing those tags isn't a great idea, but it would be harder than it looks for projects with an appreciable number of dependencies. I'm definitely in support of never writing that stupid <html> tag again.
<!-- 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.Good to know that Google recommends HTTP/1.1 optimization practices. It seems like everyone is ready to spew dozens/hundreds of tiny files over HTTP/2, though the performance rationale is dubious at best.
Because if not, then by following Google's advice here we are creating the new Internet Explorer.
For example, it keeps your indentation level flat here.
> For file size optimization and scannability purposes
Omitting tags means less transfered bytes means faster websites. If the browser can forgivingly parse HTML like this, why not take advantage of it?
Of course, it doesn't sit well with me either. This'll take some time to digest, but it is interesting to consider.
Perhaps HTML could have been better designed with performance in mind. Every tag you open (i.e. <foo>) you're supposed to close (i.e. </foo>) which is quite redundant in terms of bytes when you think about it. It is easy to imagine markup languages that minimize the number of bytes the client has to transfer.
Cutting out optional tags will improve page size, download speed etc; something that's obviously important when you're serving so many billions of users.
HTML has been deprecated in favor of Google Markup Language (GML).
They're seriously going to say that removing `<html></html>` is a file size optimization? Why does this make it easier to scan?
You can view source, and they post it to GitHub.
https://github.com/google/styleguide/blob/gh-pages/htmlcssgu...
On a more objective note, if you need omit the head and body tags to get more performance, something is very wrong with your page/tech whatever.
Maybe consider removing all those Google Fonts, all that Google tracking scripts, FB too and since you are at it, consider deleted Google Adsense if you can, since those $4.84 per month are costing you and us a whole more than the Billions in revenue Google gets.
Sorry for the saltiness, but I'm really getting fed-up with the arrogance of these childish oligarchies.