google / google/styleguide

HTML Guide: Outdated recommendation to not use 'type' in script - not accounting for type=module

Open
#547 1 comment 0 reactions 0 assignees View on GitHub
lang:html
Dominant language
HTML
Stars
39.6k
Forks
12.9k
Avg merge
42m
Merged PRs (30d)
15

Description

As per the title. [This section](https://google.github.io/styleguide/htmlcssguide.html#type_Attributes) suggests that the only reason to use `type` in HTML5 is using a non JavaScript language, but `type=module` is actually a first-class HTML5 citizen, and it has concrete consequences for the behavior, modern features (e.g. being able to use `import`s) and performance (see e.g. [MDN docs](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-type)).

~~This guide has even lead some people to [mistakenly think that the modules themselves are something that HTML5 obsoleted](https://stackoverflow.com/questions/436411/where-should-i-put-script-tags-in-html-markup/24070373#comment83495061_24070373).~~ UPDATE: This was actually [my confusion due to that comment being made on a different version](https://stackoverflow.com/questions/436411/where-should-i-put-script-tags-in-html-markup/24070373#comment109113367_24070373).

So, admittedly, my bad with the justification, but I guess this statement is still not quite true:

_"Omit `type` attributes for style sheets and scripts."_

If deciding to act, the recommendation should probably make its wording more precise, e.g.:
_Omit `type=text/css` for style sheets (unless not using CSS) and `type=text/javascript` for scripts (unless not using JavaScript)._

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.