Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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>

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top