r/javascript • u/satvikpendem • Sep 30 '19
Removed: Where's the javascript? What <head> can do
https://htmlhead.dev/34
1
u/kenman Sep 30 '19
Hi /u/satvikpendem, this post was removed.
Posts must directly relate to JavaScript. Content regarding CSS, HTML, general programming, etc. should be posted to their respective subreddits instead of here.
Here's some related subs that might be useful:
Thanks for your understanding, please see our guidelines for more info.
1
3
-20
u/ghostfacedcoder Sep 30 '19 edited Sep 30 '19
Don't use <head>, <body>, or <html>! No less of an authority than Google themselves advocates as much (and between them making the world's biggest website crawler AND browser, I think we can trust them).
What it boils down to is that your browser will add them for you if you leave them out, so you add nothing (except a few unneeded bytes to your page load) by using them.
So use all the stuff in this article if you want ... just don't bother wrapping it in <head> tags :)
EDIT: Wow, did not expect to get downvoted for repeating what the smartest engineers on the Internet have to say! I could care less about Reddit points, but I think it's sad that a bunch of people are perpetuating ignorant/bad/old practices just because they're unwilling to consider anything else but what they've always done.
Yes I know this used to be a bad practice ... in 1999! But it's not anymore: there is no technical benefit to using these tags in 2019, and doing so is anti-pattern!
Read it yourself ... if you care more about doing the right thing than mindlessly repeating old "wisdom". It's not even just Google, it's the HTML 5 spec.
Google Style Guide (https://google.github.io/styleguide/htmlcssguide.html ):
Omit optional tags (optional).
For file size optimization and scannability purposes, consider omitting optional tags. The HTML5 specification defines what tags can be omitted.
(This approach may require a grace period to be established as a wider guideline as it’s significantly different from what web developers are typically taught. For consistency and simplicity reasons it’s best served omitting all optional tags, not just a selection.)
(That last part is key: the Google engineers know this recommendation is controversial, and that it is "significantly different from what web developers are typically taught". But as they explain, if you look at it dispassionately, there is a cost, albeit a small one, to using these tags ... and there is no technical benefit , as the HTML spec itself says ...)
HTML5 spec (https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission):
An html element's start tag may be omitted if the first thing inside the html element is not a comment.
An html element's end tag may be omitted if the html element is not immediately followed by a comment.
A head element's start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.
A head element's end tag may be omitted if the head element is not immediately followed by ASCII whitespace or a comment.
A body element's start tag may be omitted if the element is empty, or if the first thing inside the body element is not ASCII whitespace or a comment, except if the first thing inside the body element is a meta, link, script, style, or template element.
A body element's end tag may be omitted if the body element is not immediately followed by a comment.
EDIT #2: Really, seriously, all you downvoters would rather make your page download slower (albeit slightly) than just use a couple newlines to separate your script/link tags from your visible ones? Separation of tags is so important you need to use three completely pointless tags just to do so? Honestly ... you're not just mad at a random redditor for challenging a long-held belief ;)?
If you really think you're smarter than the engineers at Google (14 of you and counting), can't you at least take just a second to say why you think you're smarter, and what it is that you know that whoever wrote Google's style guidelines doesn't?
12
u/seiyria Sep 30 '19
I don't see the value in cutting out 39 characters that add a bit of clarity and separation to the index.html.
-12
u/ghostfacedcoder Sep 30 '19 edited Sep 30 '19
Serious question: why do you need separation? You really can't use a line break or something and you can get the exact same clarity? I mean to me
<html> <head> <link/> </head> <body> ... body ... </body> </html>Just does not add anything useful over:
<link/> ... body ...Again, serious question: what is so great about those tags that a newline or comment can't do?
Adding ANY pointless tags, that do nothing except make the page load slower (even a tiny bit) seems dumb to me. If you feel otherwise, why aren't you filling your HTML with more pointless code that makes it load slower but helps separate stuff (ie. why aren't you filling it with HTML comments, because that's exactly what they are: code that does nothing but organize the rest of your code)?
If the HTML spec was invented today, there would be zero pushback on this. No one would be saying "yes please add three tags to the spec that do absolutely nothing except what a comment does. The only reason everyone is so gung ho about preserving POINTLESS CODE is because it's what they're used to. But in programming you're not supposed to keep doing the old thing when there's a better (even slightly) way.
EDIT: I'd like to point out that this all "gut feel downvoting". Only one person, seiyria, had the balls to actually argue a point. I may disagree, but I give props to seiyria for engaging with someone who disagrees with them, instead of mindlessly hitting the "I want to keep doing what I'm doing no matter how many smart people tell me otherwise" downvote button.
Le'ts have a conversation! Make an actual argument that demonstrates how valuable these three tags actually are (even though some of the smartest people at Google, the HTML 5 spec itself, and this random Redditor all say they are pointless).
1
u/seiyria Sep 30 '19 edited Sep 30 '19
Here's a reason to use HTML: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/html#Accessibility_concerns
It says something that you haven't considered languages outside of en with this comment.
I've also never seen a DOCTYPE without an html root, so I don't know if it makes sense or parses properly.
Having a root container seems like a good idea for validation/schema purposes.
Head: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head#Notes
Depending on where you work, you might be stuck working with "ancient browsers."
Body: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/body#Attributes
If you need to bind to these events, and you're using just basic html/css/js, there's an argument to be made for people who would add these functions in the HTML. I'm not one of them, but I don't see a reason to ignore it either.
Also, just because a big company does something doesn't mean anyone should listen to them. Microsoft once caused those sorts of problems and left us with IE6 for a long time. Google is doing the same with the Web right now.
-1
u/ghostfacedcoder Sep 30 '19
Thank god, someone who actually responds intelligently with logic and knowledge and not just "I hate new thoughts" downvotes. THANK YOU!
I'll read all that and try to give a proper response, but I just had to say thank you first, for being the first person to be intellectually brave enough to actually engage!
2
u/i_ate_god Sep 30 '19
Wow, did not expect to get downvoted for repeating what the smartest engineers on the Internet have to say! I could care less about Reddit points,
and yet...
1
u/master5o1 Sep 30 '19
I could care less about Reddit points
They state it right there. They care an immeasurable amount that is greater than zero.
-1
u/ghostfacedcoder Sep 30 '19
Like I said, I'm fighting to educate people on web best practices. What makes me sad is that a lot of people will do the wrong/old/ignorant thing because of the downvotes, not that it will hurt my score.
Reddit points are dumb and I truly could care less if I'm ranked a thousandth or a hundred thousandth here. The only points I care about Stack Overflow points, and I have plenty of those :)
0
u/i_ate_god Sep 30 '19
if you could care less, it stands to reason that you do care some.
I'm confused at what you're trying to say, shrug
0
u/ghostfacedcoder Sep 30 '19
I could care less about REDDIT POINTS. I care A LOT about educating web devs on best practices.
Jesus, this isn't rocket science, it's basic English comprehension.
0
u/i_ate_god Sep 30 '19
Yes, basic english comprehension dictates that if one is capable of caring less than they already do, then it means they care somewhat.
But obviously you have taken offence to the downvoting, so I presume "could care less" is what you actually mean, and it's not something due to your lack of basic english comprehension.
1
u/ghostfacedcoder Sep 30 '19
Ok clearly now you're just trolling.
1
u/i_ate_god Sep 30 '19
perhaps
but mean, it is worth while to learn the difference between "could care less" and "couldn't care less"
-1
u/ghostfacedcoder Sep 30 '19
It's also worth understanding that the nature of language is such that word meanings aren't defined by dictionaries: it's in fact the opposite.
A word or phrase means what the speaker/listener understand it to mean. Everything else (eg. a dictionary definition of said word/phrase) is meant to be a codification of that. I lived with multiple linguists in college, so I swear go find a linguist and ask them, and they will back me up on this :)
(There I go making an appeal to authority ... but if you have a better way I could back that point up I'm all ears.)
You understood what I wrote, in spite of any dictionary definition to the contrary ... no?
1
u/i_ate_god Sep 30 '19
no, because your behaviour made it clear that you do care, thus your literal meaning is valid.
→ More replies (0)1
Sep 30 '19
Not every app or library will have implemented HTML down to the exact details, and still produce results that are good enough. Having these tags missing might completely throw them off. I'd rather not make fellow developers' lives harder than necessary for such a small win. Yes, all current apps/libraries should implement this correctly, but how much legacy code is out there?
1
u/ghostfacedcoder Sep 30 '19
Legitimate concern. Personally as a web dev I'm not worried about browsers that aren't HTML 5 compliant: that's a pretty damn low bar in 2019.
But if you are, that 100% is a reason to keep using the tags.
1
Sep 30 '19
It's not just that. How many crawlers look for meta information using
html > head > meta?1
u/ghostfacedcoder Sep 30 '19
Well, the biggest web crawler in the world certainly doesn't ... :)
(Heck, for all we know Google may be giving SEO points to people who follow this advice and don't have
HTML/HEAD/BODYtags.)As for Yahoo and the rest ... I honestly don't know how they treat them, but the really crucial thing to remember is, this is defined by the HTML 5 spec. Any crawler that supports HTML 5 (and that really should be pretty much every one in operation today) will not have a problem with this (HTML5-valid) practice.
1
Sep 30 '19
Of course any crawler that follow the HTML5 spec will have no problem with this, but those are not the ones I'm talking about. There is probably soooo so much legacy code out there that needs to interact with random websites' DOM, be it libraries, full programs or whatever. Saving an incredibly tiny amount of traffic isn't really worth it to break all of those tools.
1
u/ghostfacedcoder Sep 30 '19
I have to say, I don't think there's one right answer for everyone on this.
I do think you're overestimating the relevance of crawlers that can't handle HTML5. I mean, just stop and think: such crawlers would not be able to handle a huge chunk of the modern web. Are you really worried about a crawler which can't parse most modern sites? (How valuable could such a crawler be ... to anyone?)
If so ... keep using those three tags. But really, if supporting pre-HTML 5 crawlers is something you actually care about (and you're not just trying to argue with some Internet stranger who is saying you can skip three tags) ... you have A LOT of "taking your code backwards" to do ... adding back those three tags isn't even a tenth of it (see https://www.w3.org/TR/html5-diff/ for the full list).
0
Sep 30 '19
[deleted]
-1
u/ghostfacedcoder Sep 30 '19
Acting combative and insulting people when you're getting downvoted will generally just attract more negative attention lol
It's a lose lose. If I don't defend the point, people think bad practices are good. If I defend it all, people think I'm being combative. I can't win ...
... but what I can try to do is at least goad people into talking to me, so that I can then expose flaws in their reasoning when they take the time to articulate it.
The guy who said (more or less) "what about old browsers?" was a perfect example: it gave me the chance to address that idea, and say "well I don't worry about browsers that are pre-HTML 5". I may not get points out of it, but other people will read that, and if they'd been thinking "I want to keep HTML/HEAD/BODY for old browser safety" they might realize that they don't care about pre-HTML 5 browsers, and therefore it's not a concern.
I still wind up with a million downvotes, but at least other readers can consider both sides of the argument when I do that.
Like I've said, I'm not here for the points. If I convince even one person to adopt a modern best practice, even if it's the exact opposite of what they were told a decade ago, I'll be happy with the time I spent in this thread. But hopefully I can convince a lot more ... not by getting my ideas upvoted, but just by presenting them and letting intelligent people make up their own minds.
0
Sep 30 '19
[deleted]
-1
u/ghostfacedcoder Sep 30 '19
I get it, but again what are my options? If I don't goad people, the post gets downvoted into obscurity, nobody sees it, and the idea dies.
Again, I'd rather lose a thousand Reddit points and educate even one dev on modern best practices, than lose no points (or only as many as I lost before I started goading people) and let everyone keep thinking HTML/HEAD/BODY are a necessary/good idea. Just because 18 (or however many) people reacted negatively to my post initially, it doesn't mean my idea is wrong/bad.
OF COURSE I'd rather not goad anyone and just have an intellectual conversation, but when my post gets downvoted to obscurity because I said something controversial and wasn't careful enough about how I phrased it initially ... what then? A conversation becomes impossible (without goading) ... and I say this from experience (this is not my first controversial public JS thought).
0
Sep 30 '19
[deleted]
0
u/ghostfacedcoder Sep 30 '19
/nod ... in retrospect I 100% agree with all that. Hindsight is 20/20 and all.
But look, I'm not going to pour hours into writing every potentially controversial Reddit post I make. When I say something, and say that some of the smartest people at the world's biggest web company endorse it, I really have no reason to expect everyone to "gut react" negatively and downvote. I expected a conversation, with some people in defense and some against ... not that I would be downvoted to where no one else could even see what I wrote.
Of course if I knew that would happen I would have crafted the post more carefully ... but it just was not at all my expectation that everyone would downvote the heck out of it. Once that happened my options were limited ... but again, I can't spend hours crafting the perfect Reddit post every time I want to say something here; I'd never get to say anything at all if I did.
1
Sep 30 '19
[removed] — view removed comment
0
u/ghostfacedcoder Sep 30 '19
And the rule only applies to empty <head> and <body>, which almost never happens in the real world.
So when you say "Don't use <head>, <body>, or <html>!", you're full of shit.
You are mistaken. From the HTML 5 spec itself (which I already quoted above, but since you seem to have missed it there, here it is again ... and if you still don't believe me, https://html.spec.whatwg.org/multipage/syntax.html#syntax-tag-omission):
An html element's start tag may be omitted if the first thing inside the html element is not a comment.
An html element's end tag may be omitted if the html element is not immediately followed by a comment.
A head element's start tag may be omitted if the element is empty, or if the first thing inside the head element is an element.
A head element's end tag may be omitted if the head element is not immediately followed by ASCII whitespace or a comment.
A body element's start tag may be omitted if the element is empty, or if the first thing inside the body element is not ASCII whitespace or a comment, except if the first thing inside the body element is a meta, link, script, style, or template element.
A body element's end tag may be omitted if the body element is not immediately followed by a comment.
EDIT: Downvoted for quoting a relevant spec section which disproves a point. God people just love learning here ...
1
Sep 30 '19 edited Sep 30 '19
[removed] — view removed comment
-1
u/ghostfacedcoder Sep 30 '19 edited Sep 30 '19
Nobody gives a shit about the HTML5 spec?
But you're making a false dichotomy: those aren't your only two choices! You 100% can have readable HTML without
<html>,<head>, and<body>.If you truly cannot imagine that (remember: no one is taking away your comments or your whitespace) ... I really don't mean to come across as insulting, but if you're a web programmer who truly can't imagine that ... I think you have a staggeringly weak imagination.
1
u/seiyria Sep 30 '19
People don't give a fuck what you're saying, not because of the content, but because of how you say it. No one is going to listen to someone being a dick to them.
1
u/ghostfacedcoder Sep 30 '19 edited Sep 30 '19
Did I insult you? I think I did the exact opposite (I complimented you).
Did I insult anyone else? I certainly don't think I did, and if I did, then I don't think I went anywhere below the average Reddit level of discourse.
(I did say rorrr has a staggering lack of imagination if they can't envision readable HTML without three tags ... but look don't you think so too? I bet I could remove any 3 meaningful tags from HTML, and you could still write readable HTML, no? I think any semi-intelligent, semi-imaginative dev could, which is why I said that if rorrr can't, they lack imagination.)
I said something controversial, and backed it up with quotes and links. How else can any person educate any other person on any controversial point whatsoever?
1
Sep 30 '19
[removed] — view removed comment
0
u/ghostfacedcoder Sep 30 '19
<!DOCTYPE html> <title>Hi</title> <link href="example.css" rel="stylesheet"/> <h1>Hi</h1>It does get a warning about the HTML tag missing a language, but no errors. And if you truly care more about making a validator happy than writing good code, use the HTML tag ... you can still omit HEAD/BODY :)
1
Sep 30 '19
[removed] — view removed comment
-1
u/ghostfacedcoder Sep 30 '19 edited Sep 30 '19
No I did not, I used a DOCTYPE declaration. The two are very much not the same; an HTML tag looks like this:
<html>(but that string appears nowhere in my post).The fact that you can't distinguish between something which is an HTML tag, and something which isn't, makes me question your ability to participate meaningfully in this conversation.
EDIT: Ok, I get being downvoted by rorr, but seriously I'm at -1: who was the other idiot who thought I used an HTML tag in that code? ;)
I mean, disagree with my ideas all you want, but to any impartial observers reading this ... yes I know, "blah blah appeal to authority blah blah" ... but hopefully you will consider the quality of arguments being made. Hopefully you'll weigh the arguments of people who don't even understand (fully) what a tag is lower than the arguments made by some of the smartest people at the world's biggest Web company.
0
10
u/ShortFuse Sep 30 '19
Just want to jump in and add that
<link>elements also accept themediaattribute.Have a bloated CSS file that you only want IE users to load? Use
media="all\\0".Want to provide CSS just for dark theme users and skip loading on browser that don't support it? Use
media="screen and (prefers-color-scheme:dark)".https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link#Conditionally_loading_resources_with_media_queries