Use of type and/or language in script-tag

E

Erwin Moller

Hi group,

I am a bit cconfused with the different tags I encounter to start a script.
I used to use: language="Javascript"

Nowadays I use: type="text/javascript"

I did see some javascript1.2 (i think) too, but never used that.

But when I let my favorite editor (Eclipse) do some codecompletion I get:
<script language="JavaScript" type="text/javascript"
src="jsfile.js"></script>

Forget about the src for a moment.
I see 2 definition in the same tag.

Is that ok?
And on a sidenote: Am I safe when I use the modern type="text/javascript"
only? The answer probably depends on the browser.

Where can I find some coherent information?
Some overview with browsers and javascripttags and such.

I did find some information already but I am looking for a overview/advise.

Thanks for your time!

Regards,
Erwin Moller
 
M

Martin Honnen

Erwin said:
I am a bit cconfused with the different tags I encounter to start a script.
I used to use: language="Javascript"

Nowadays I use: type="text/javascript"

I did see some javascript1.2 (i think) too, but never used that.

But when I let my favorite editor (Eclipse) do some codecompletion I get:
<script language="JavaScript" type="text/javascript"
src="jsfile.js"></script>

Forget about the src for a moment.
I see 2 definition in the same tag.

Is that ok?
And on a sidenote: Am I safe when I use the modern type="text/javascript"
only? The answer probably depends on the browser.

Well, <script> is an element in HTML 4, you can find the syntax for HTML
4 on http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.1 where you
should find that the type attribute is mandatory while the language
attribute is deprecated. Thus if you want to author your HTML pages
according to the HTML 4 standard then you at least need
<script type="content type for your script language">
However there is no MIME type registered for JavaScript as far as I know so
<script type="text/javascript">
is what is common use but nothing standardized. Indeed some
implementations for script in SVG or XML pages use or at least allow
type="text/ecmascript".
As for HTML pages and browsers I think you are safe with
<script type="text/javascript">
modern browsers like IE5+, Netscape 6/7, Opera 7 support that and older
ones like Netscape 4 might not but default to assuming script is
JavaScript anyway.
 
M

Michael Winter

I am a bit cconfused with the different tags I encounter to start a
script.
I used to use: language="Javascript"
Bad.

Nowadays I use: type="text/javascript"

Very good.
I did see some javascript1.2 (i think) too, but never used that.

Oh so wrong! Specifying a version seems to cause odd parsing rules to be
invoked (for example, = meaning assignment *and* equal to[1]) and limiting
the available methods and properties that are available. Most people don't
understand the consequences of either.
But when I let my favorite editor (Eclipse) do some codecompletion I get:
<script language="JavaScript" type="text/javascript"
src="jsfile.js"></script>

My editor used to do that, but I fixed it. I don't know if you can in
Eclipse - look in the preferences.
Forget about the src for a moment.
I see 2 definition in the same tag.

Is that ok?

The language attribute is deprecated. Last week, I went on a trek through
the older HTML specifications to see exactly when this deprecation
occurred. This is what I found:

In version 2.0, there was no SCRIPT element.
In version 3.2, there were no formal attributes to the SCRIPT element.
In version 4.0, all of the current attributes were present, and language
was already deprecated.

What I conclude from that is that the language attribute was proprietary
(at a guess, probably Netscape) and was never a recommended part of the
HTML language. When the need to specify the scripting language was
identified, it was determined that the language attribute was inadequate
(values were inconsistent) so it was added to the specification, but at a
deprecated status. The type attribute, using MIME type values, was
recommended in its place. As such, it has never really been OK to use it,
apart from in the early days of version 4.0 and earlier, though strictly
for backward-compatibility purposes only.

[If I am totally off the mark, or if there is further information on this
subject, I would be interested in hearing it.]
And on a sidenote: Am I safe when I use the modern type="text/javascript"
only? The answer probably depends on the browser.

The type attribute is not modern. It first appeared in v4.0, which was
released just over six years ago. You will not encounter any problems
using it[2].
Where can I find some coherent information?

Just follow the specifications. In everything, that is the best you can
do. If there is an identified problem (such as IE's general lack of
standards support), then you should embark on a workaround for that
situation. I don't think it is, or should be, the author's job to cope for
broken or obsolete browsers (unless it is really in the interest of the
project).

That would be my assessment. Not normative, nor necessarily recommended,
by any stretch of the imagination.

Mike


[1] Mentioned by Randy Webb in an off-topic (at the time) discussion with
Richard Cornford and Lasse Nielsen.
[2] Even if a browser doesn't understand type, it is fairly guaranteed
that the browser will default to JavaScript anyway.
 
E

Erwin Moller

Thanks a lot Mike!

(offers Mike a virtual beer)

You clarified that tricky stuff quite nicely and at a level somebody who
didn't dive into it for a week (=me) can understand. :)

Darn, by the way, I called something 6 years old 'modern'.
I guess I am getting old. :p

Thanks for your time!

Regards,
Erwin Moller
 
M

Michael Winter

Thanks a lot Mike!

(offers Mike a virtual beer)

Teetotal I'm afraid, but it's the thought that counts. :)
You clarified that tricky stuff quite nicely and at a level somebody who
didn't dive into it for a week (=me) can understand. :)

I would like to remind you (for my sake as much as yours) that that was
mainly conjecture. I couldn't really find anything concrete. The
discussions about the language attribute either occurred behind closed
doors, or on the public mailing list[1] and the last time I tried to
search that, the engine rolled over and died, so I won't be trying again
in a hurry.

I'm hoping that someone else will either confirm my analysis (either
explicitly or through silence), or correct it. In any case, the debate
should be over historical accuracy, or lack thereof. The main theme should
still be the same: use type and avoid language.
Thanks for your time!

You're very welcome.

Mike


[1] By that, I mean there was nothing in the specification notes.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Michael Winter <[email protected]
d> posted at Thu, 19 Feb 2004 13:04:08 :-
[2] Even if a browser doesn't understand type, it is fairly guaranteed
that the browser will default to JavaScript anyway.

Unless the previous script on the page was not javascript (e.g.
VBscript).

I've not yet found anything in VB that looks useful for a mainly-JS
page, but a bit of JS could be used in a VB page for getTimeZoneOffset()
 
T

Thomas 'PointedEars' Lahn

Erwin said:
But when I let my favorite editor (Eclipse) do some codecompletion I get:
<script language="JavaScript" type="text/javascript"
src="jsfile.js"></script>

Forget about the src for a moment.
I see 2 definition in the same tag.

Is that ok?

I presume you are writing about the "JavaScript *" templates of
the PHPeclipse plugin for eclipse, which is the only editor plugin
that I know of to do code completion and thus I happen to use, too.
If that is the case, you can change these templates with Window,
Preferences, PHP, Templates, <script, Edit, ..., OK, OK.


HTH & HAND

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top