detecting JS language mode for tools

Domenic Denicola domenic at domenicdenicola.com
Mon Jan 27 21:01:13 PST 2014


From: es-discuss [mailto:es-discuss-bounces at mozilla.org] On Behalf Of Brendan Eich

> Examples? What is the specified grammar?

>From [the HTML spec][1]:

> The `type` attribute gives the language of the script or format of the data. If the attribute is present, its value must be a [valid MIME type][2]. The `charset` parameter must not be specified. The default, which is used if the attribute is absent, is `"text/javascript"`.

Then there's a bunch of other text regarding how the `type` attribute translates into MIME types and how mime types end up translating to "supported scripting languages", ending up at [3].

---

My understanding of what's been specified here, codified from legacy, is that browsers (since the dawn of time) always interpreted either missing `type` attribute or "text/javascript" as instructions to execute JavaScript code, and most other things as inert and ignored.

There's a bit of a gray area involving all the other "aliases" for text/javascript, e.g. some older browsers probably don't support text/livescript, while others probably don't support text/jscript.

The upside is that, as Arv says, you can put any string you want in there, and browsers will cope just fine by ignoring it unless it's one of the specific types that maps to JavaScript per [3]. The spec has authoring conformance criteria that it must be a MIME type. But the actual codified behavior is closer to "if it's in this list of strings, or absent, you get JavaScript; otherwise it gets ignored, unless the browser wants to implement VBScript/Dart/etc. using some other magic string."

[1]: http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element
[2]: http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html#valid-mime-type
[3]: http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#support-the-scripting-language



More information about the es-discuss mailing list