DEV Community

Discussion on: TIL: You can leave out html, head, and body tags in your HTML.

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

So out of curiosity, I tested this locally and you're right: Omitting head/body tags does reduce the network request size for the HTML document. However, the part that I don't understand is this:

One of many small optimisations that add up to a lot.

Optimizations at the byte level are useless—optimizations at the kB and MB level, on the other hand, can make a significant difference in load times.

Besides, most sites these days will have proper HTML scaffolded out with JS frameworks or SSGs anyway, so there's no point in advocating for this approach.

One last thing worth mentioning: You can have link and script tags in the body, and there's sometimes a very good reason for doing so (e.g., deferring JavaScript).

Collapse
 
shadowfaxrodeo profile image
Nathaniel

Well, kilobytes are made of bytes. If you have 100 similar optimizations, you'll start seeing the differences. Especially once 1 million people visit your site.

You can still place link and script tags in the <body>. So long as they're placed after an element that isn't allowed in the <head>. Usually when deferring scripts you place them at the very end of the document, so in that case it will work the same.

I totally get why someone wouldn't bother doing this. But if you're already minifying html, which you definitely should do, then it's as simple as adding something like omitUnnecessaryTags:true to your config.

Collapse
 
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan • Edited

Well, kilobytes are made of bytes. If you have 100 similar optimizations, you'll start seeing the differences.

That's a bit like saying that $1,000,000 is made of $1 bills (technically true), and you'll eventually become a millionaire if you collect enough $1 bills (not necessarily true, and almost always false).

Every optimization incurs a cost—on maintainability, legibility, and time. There are far better ways to minify your HTML and other assets, like with compression.

Think of this in terms of opportunity cost. Why save 39 bytes when you could save more, by working on more meaningful optimizations? Time is money.

Thread Thread
 
shadowfaxrodeo profile image
Nathaniel

I totally understand what you're saying. I personally enjoy little things like this so I'm happy to do them. i wouldn't expect every developer to take the time to do this on every individual website.

But there are situations where doing this would save 39 bytes on lots of other people's sites. Like if you're building a template of some kind. then you really ought to take the time to do this sort of thing.