30

I was looking at the W3C specs for the script tag, and I noticed you can specify VBScript and TCL as a language type. This is extremely new to me; I've only ever seen Javascript used with the script tag.

Why aren't other languages more commonly used, and is there a complete list of languages you can use within this tag?

3 Answers 3

35

You can put anything you want in there. That's the whole point of MIME types.

The question is of course whether or not your user's browser can actually interpret it. But that's not really specific to the <script> element. My browser, for example, only understands CSS for stylesheets, others also understand XSLT. My browser only understands HTML, XHTML, HTML5, MathML and SVG for documents, others also understand PDF or don't understand MathML. My browser understands alpha-transparent PNGs, others don't. Before the GIF patent ran out, there were some browsers that didn't understand GIFs, while others paid the licensing fees (or used the patent illegally or were developed in jurisdictions where software patents are illegal) and did understand GIFs. Some browsers understand H.264 videos, others Theora.

In general, the only language that is guaranteed to be understood by all browsers, is ECMAScript 3rd Edition. Most browsers also understand some subset of JavaScript.

Many versions of Internet Explorer understand VBScript.

The CoffeeScript compiler can be compiled to ECMAScript and embedded into a website, so that you can use CoffeeScript in your page via the text/coffeescript MIME type.

There's a project called HotRuby, which is a YARV bytecode interpreter written in ECMAScript. It allows you to use text/ruby.

Microsoft has a project called Gestalt, which uses IronRuby and IronPython running on top of the DLR inside Silverlight to provide support for text/python and text/ruby (and presumably any language that can run on top of the DLR, e.g. Scheme, Smalltalk, PHP, Tcl.)

Mozilla had a project a while back called IronMonkey, I believe, which embedded multiple popular execution engines, such as MRI Ruby, CPython, Perl and others into Firefox, allowing the use of all those languages for browser scripting.

I remember reading somewhere that someone built a plugin for tcc (tiny C compiler) support, which would allow you to use text/c.

Just a couple of days ago, Miguel de Icaza (the creater of Mono) suggested that the ISO CLI should be added to the browser as a scripting platform, allowing you to use CIL bytecode for scripting via an application/cil MIME type.

3
  • 2
    This is a brilliant answer for historical references, but the latest spec actually dictates that the script tag contains either JS, or data blocks. (How data blocks are used by the browser vendor and other scripts is another question, though. See the spec for an example of embedding game map data in a<script type="text/x-game-map"> tag.)
    – wlnirvana
    Commented Apr 3, 2021 at 6:53
  • This seems a very strange backwards-incompatible restriction for a spec that tries very hard to not break backwards-compatibility. How do you use scripting languages other than ECMAScript, then? Commented Apr 3, 2021 at 7:04
  • 2
    I doubt if this is really "backwards-incompatible". The spec says Authors must use a valid MIME type string that is not a JavaScript MIME type essence match to denote data blocks, which seems to suggest types like text/c and text/ruby still be valid - it's just that they are now termed as "data blocks". Then it is probably up to the browser or other scripts to handle these data blocks, where other scripting languages may come into play.
    – wlnirvana
    Commented Apr 3, 2021 at 7:29
6

Why aren't other languages more commonly used, and is there a complete list of languages you can use within this tag?

Because javascript is supported by all browsers unlike VBS which is supported by only IE.

Note: The language attribute is deprecated now, use the type attribute only eg:

<script type="text/javascript">
...
</script>
1
  • 2
    This is why I referred to it in my question as "language types". While not technically a correct phrase, I am aware that "language" is depreciated and wanted to convey that (though it's difficult). Nonetheless, this is an important reminder because the attribute is depreciated, yet I still see it occasionally...
    – Corey
    Commented May 20, 2010 at 8:25
1

You can specify any language the browser can interpret, I imagine. At the moment, though, text/javascript is the only one supported across browsers.

VBScript is available in IE under some circumstances and thus (obviously) limited to Windows and that browser. It's not really an option if you want to build web sites that are to run across browsers and platforms. I think you can also use Windows Script Host scripts in IE, but I'm not familiar with the details.

Where have you seen an implementation of TCL? That would be interesting to see.

For completeness' sake, PHP understands <script language="php"> tags to specify the beginning of a block of PHP (reference). This doesn't really count in your list IMO as it's caught and interpreted on server side, and it only supports the deprecated language= syntax, but still.

5
  • TCL? I've never seen it used anywhere... however, that W3C page has an example of it. That is what brought up my question; it's very strange.
    – Corey
    Commented May 20, 2010 at 8:27
  • @Corey can you post a link? I can't see it, I'm looking here: w3.org/TR/REC-html40/types.html#type-script
    – Pekka
    Commented May 20, 2010 at 8:30
  • Scroll down a bit: w3.org/TR/REC-html40/interact/scripts.html#h-18.2.2.3
    – Corey
    Commented May 20, 2010 at 8:31
  • @Corey oh, I must have mistyped while searching. Weird! I've never seen TCL support, at least not in a browser.
    – Pekka
    Commented May 20, 2010 at 8:36
  • It is weird. It makes me wonder if there's any documentation out there on what languages are supported in the tag, and what browsers support them.
    – Corey
    Commented May 20, 2010 at 8:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.