langua= vs type=

J

Jim Davis

Michael Winter said:
On 27/08/2005 23:26, Jim Davis wrote:

[snip]
For example what code would detect the "typeof" operator (only
available in 1.1 and above)? How about the delete operator - which
only works correctly in 1.2 and above?

Exactly why would you need to? Browsers that don't support them have an
object model that is too primitive to be useful, if they are in use at
all.

So... we should do feature detection only if those features are easy to
detect? ;^)

Those are only examples: there are features like that every version of the
language and there will no doubt be many more to come. There are features
only available in 1.4 and those only available in 1.5 and there will be new
ones only available in 1.6.
That would /mainly/ affect very early NN4 versions, so again it would seem
irrelevant.

But, again, don't discount the question for the examples. There are
definately features that are difficult to detect and plan around. A useful
way to determine supported language version is "a good thing" despite the
fact that the method we have for detemining this is is flawed.

Jim Davis
 
R

RobG

very good point. A look over the major sites shows that:

amazon.com uses both and sometimes just the language=.

applec.om uses just the language=.
yahoo.com uses just the language=.
orkut.com uses just the type=.

msn.com sometimes uses both, sometimes one or the other.
ebay same with msn.com.

so far it seems the language= is more popular...

Those using language= does not always indicate a version.

one wonders if there is a pattern for sites that uses both sometimes
one of the other.
my guess is that it's rather random...

Unfortunately, that's all you have - a guess. Does anyone know why
those sites use those particular script element attributes? If asked,
would anyone at the site have an answer they'd be prepared to share with us?

Large slabs off all the sites seem to be cobbled together from all sorts
of sources (if the randomly distributed copyright and IP claims are to
be believed), much of the UI seems to have been 'developed' elsewhere
using a variety of publishing tools.

My guess is that any legitimate reason for using type or language for
any particular script has long since been forgotten on the basis that if
it ain't broke, don't fix it. In other cases, mixing language and type
(or ignoring them altogether) does not cause them any significant issues
at all.

[...]
 
R

Richard Cornford

Michael Winter wrote:
[1] The earliest NN4 version I have installed is 4.77. I
might check an earlier version tomorrow (4.08). I expect
it will also support the type attribute, but I'll follow
up if it doesn't.

As I recall those older Netscape browsers do not support the type
attribute as such, what they do is ignore an unrecognised attribute, and
default to assuming javascript in the absence of any other instructions.
Which is why you can get away with <SCRIP> in most cases, as all
browsers that can be scripted default to assuming javascript. That is a
good thing as it means that the required type attribute is harmless when
it is not understood.

Richard.
 
R

Richard Cornford

Jim said:
Well... it cannot be validated without errors. It can still be
validated however!

I suppose that is the distinction between validation as running the
mark-up through a validator, and validation as having the validator
declare the result as valid.
And, since the error is both clear, and (if you know what you're
doing) expected it's hardly an enormous inconvienence.

The error is clear and can be disregarded as not significant. There are
attributes that are not part of HTML that you may be willing to dismiss
in a validator error report, such as the galleryimage attribute, which
the W3C validator will flag as an error, but if it has been used it has
been used for a reason (hopefully). But why have the validator churn out
error messages that can be avoided with no consequences for the
resulting document.
Also, of course, it will validate against a non-strict
version.

And it may validate against non-official DTDs, which is why I said so.
2. There is a risk that individuals using the language
attribute may employ the formulation -
LANGUAGE="Javascritp1.2" - and may get what they are
asking for (with all of JavaScript 1.2's divergent
behaviour)[1].

Which is a great reason to only use JavaScript1.3 or
above - not a reason not to use the attribute at all.
If you use "JavaScript1.5" you do get, in nearly all
browsers (and all the major ones) what you want - but
that's not enough.

But in "nearly all browsers (and all the major ones)" you get ECMA 262
3rd edition if you don't use the language attribute, but use only the
type attribute, so specifying a recent version number gains you little
And it costs some compatibility. I have mentioned IE 5/JScript 5; it
will not load anything higher than language="javascirpt1.3", but IE 5
does have a (more or less) workable, dynamic W3C level 1 DOM and many of
the language features introduced in ECMA 262 3rd edition. It is also not
yet so old that it is out of use entirely (even if those actually using
it would be well advised to switch to a later version (or an
alternative)).

There are really only two pros:
2) Older browsers may not understand the "type" attribute.

That doesn't matter as they default to using javascript anyway, which is
why you can get away with just said:
In some, rare, cases the language attribute is really
the only way to get the job done (as when using vbscript
instead of JavaScript in an older version of IE).

To date IE is the only browser to offer a choice of scripting language,
and it defaults to JScript. So if you use another language you need to
tell it which one, but that is not really significant outside IE only
Intranets.
Nothing at all. It's standardized, it's easy, it's ignorable by
those that don't understand it.

And those are cons of type="text/javascript"?
Too true... of course it doesn't actually DO a damn thing,
but still, it is required.

There are browser where the type attribute does do something. Such as
IE, where if you put a VBScript element at the top of a page the browser
switches to assuming script elements are VBscript instead of javascript,
but an element with type="text/javascirpt" will still be interpreted as
javascript (or, more accurately JScript, assuming the DLL is
installed/available). Mozilla also does something in response to the
contents of the type attribute, for example, a particular formulation of
type attribute gives you the XML extensions for ECMAScript.

Granted, in the vast majority of cases what a browser does in response
to encountering type="text/javascript" is indistinguishable from what it
would do if there where no attributes in the script element at all, but
that does not mean that they actually do nothing in response to it.
There isn't a browser in existence that changes it's
behavior based on this attribute.

Well there are, but that is not what I was referring to. The important
aspect of HTML validity for scripting is structural validity; the
correct nesting of the various types of elements. Documents that are
structurally invalid are subject to browser error correction during the
creation of their DOM, and no two browsers follow the same
error-correction rules (as they are non-standardised and unpublished).
It is entry possible to present an invalid document to the three most
common browsers and get 3 distinct DOM structures as a result. If you
are then trying to script that DOM coping with the differences is extra
work, and will tend to give the impression that accommodating a range of
browsers is harder work than it really is.

Structurally valid mark-up maps directly to a single DOM structure,
following well understood and standardised rules. Thus structurally
valid mark-up results in DOM structures that are more consistent across
browsers, and so easier to script. That is what is important about HTML
validation in relation to browser scripting.

Obviously a document that is reported as valid by a validator will be
structurally valid. You can have structural validity (and so a constant
DOM) alongside invalid/missing attributes, but it is easier to see that
a document is structurally valid when you don't have to look past a mass
of validity errors relating to missing required attributes.
Informed opinion can inform either decision.

Well it could, but it doesn't tend to. Searching this newsgroup's
archives for the last three years will hardly turn up any
recommendations for the use of the language attribute.
My preference (based on my informed opinion) is still to
use both with a language attribute of 1.3 or higher
depending on the script.

Version 1.3 is pointless in a world where pre-version 1.3 browsers are
not used, and later versions exclude some of the older browsers still in
use where such exclusions are not necessarily justified.

Richard.
 
J

Jim Davis

Richard Cornford said:
But in "nearly all browsers (and all the major ones)" you get ECMA 262
3rd edition if you don't use the language attribute, but use only the
type attribute, so specifying a recent version number gains you little
And it costs some compatibility. I have mentioned IE 5/JScript 5; it
will not load anything higher than language="javascirpt1.3", but IE 5
does have a (more or less) workable, dynamic W3C level 1 DOM and many of
the language features introduced in ECMA 262 3rd edition. It is also not
yet so old that it is out of use entirely (even if those actually using
it would be well advised to switch to a later version (or an
alternative)).

IE 5.x is a peeve of mine: using "JavaScript1.5" prevents it from running
some script which is exactly what I want in some cases. But there are
others. For example Opera (versions 5-7) will claim a "1.4" compatibility
and will not run code labeled "1.5".
And those are cons of type="text/javascript"?

Not at all. I've never, ever argued against using the type attribute -
never. I'm all for it. I'm a booster, you see!

(However, if we want to get pendantic there is the fun that the MIME type
"text/javascript" itself isn't exactly standardized... it was ratified and
deprecated at the same time... at the moment it's the same state as the
"Language" attribute. ;^) )
Version 1.3 is pointless in a world where pre-version 1.3 browsers are
not used, and later versions exclude some of the older browsers still in
use where such exclusions are not necessarily justified.

1.3 _or higher_ (which as we've already noted can succesfully keep versions
of IE and Opera from biting).

However, all that said you may very well be convincing me... and I'm big
enough to admit it. (Actually I'm big enough to admit it while shattering
folding chairs... but let's not get personal. ) Give me the night to think
it over but I think you've got a convert.

Just to be clear (and ramble a bit): I appreciate the conversation for the
content of it. Your arguments are (what I consider) good arguments: you
argue practically for the standard and THAT'S what convincing.

My gander is raised by those that scream "STANDARDS" and beat their chests
but seemingly have no sympathy for those trying to work in the real world
where there is sloppy support and, in some cases, hacks being the only
method for getting something done.

Personally I would REALLY like to see the standard expanded to indicate
supported language version. While there will always be browser bugs and
inconsistencies to deal with it would be vastly nicer to deal with them on a
field of level expectations. Although a MIME type to do this isn't very
attractive to me (this isn't just a browser issue: it has to do with
different levels of support in ActionScript, Windows Scripting host and
other ECMAScript containers).

I'm not naive enough to think this will actually happen... but it's still a
nice thought.

Jim Davis
 
K

Kimmo Laine

Matt Kruse said:
Answer this: Why?

Maybe your answer is, if you code to the standards and validate, then you
can expect well-behaved browsers to handle your code correctly.

You read me like an open book.
However, this isn't always the case. Sometimes, browser quirks need to be
taken advantage of. Sometimes you can add functionality to a site for
older browsers or even modern quirky browsers by 'hacking' the source,
when the browsers wouldn't have otherwise been able to handle the
functionality using the 'standards' approach.

There are certainly good arguments for validation and following standards.
In most cases, they are completely convincing and good advice. But you
also need to consider the 'big guys' and what they are doing. If they get
more hits than you can imagine, can hire the best people, can throw lots
of money at problems, and can make sites which offer advanced
functionality in many browsers, then maybe they ARE doing something right,
even if their source doesn't validate.

What do are doing right, is that they have the stuff people need from the
web. those examples given would be buying and selling stuff and searching
and communicating. I'm not a regular user of the sites so I couldn't tell
what the added functionality would be. Except for google.com, which is my
start page, I see no added functionality in unqualified source code.

I do see One Major Disadvantage in the future as I look into my crystal
ball. It's this: IE css hacks will break in the future when IE7 comes. IE
css hacks are pieces of code that hide certain style sheet properties from
IE, that it cannot handle. The code is "hidden" inside a syntax IE can't
handle. Now: IE 7 can handle the syntax, so it can see the code too. But it
can't still handle the code. Because well, let's just say that IE still
sucks. Same shit, different version number.
If you can enhance the user experience with functionality that one browser
has (say, IE) and others do not, but using this functionality causes the
source to not validate perfectly, then what would you be gaining by
removing the added functionality? Would you rather have it validate, but
remove functionality?

This is where the two of us differ. I will not implement browser-specific
code that would add functionality /if/ it caused page not to validate. So
far that has meant simply no ActiveX components. I have always achieved what
I wanted so that it does work on all major browsers and remains valid code.
 
R

Robert

Jim said:
And yet certain features are difficult to detect...

For example what code would detect the "typeof" operator (only available in
1.1 and above)? How about the delete operator - which only works correctly
in 1.2 and above? The identity operator was only introduced in 1.3 and
above and so forth.

The other posters have already answered this for me :)
I myself am sceptic towards using the language attribute for detecting
such language features.

I would like to go back to the question of the original poster. I do
think we can all agree that:

type="text/javascript"
is better than
language="javascript"

Robert.
 
M

Michael Winter

On 28/08/2005 02:25, Jim Davis wrote:

[snip]
So... we should do feature detection only if those features are easy to
detect? ;^)

Not at all. We should detect features that we need, that are likely to
be missing and, with the exception of some built-in methods (in
Array.prototype, for instance), these features are almost exclusively in
the object model not the language.

Yes, there are language features that can often be missing in some
earlier browser versions (not limited to exception handling, the
instanceof operator, property/prototype examination methods), but these
can be happily avoided for the most part.

[snip]

Mike
 
J

Jim Davis

Robert said:
I would like to go back to the question of the original poster. I do think
we can all agree that:

type="text/javascript"
is better than
language="javascript"

Well - I've been convinced.

Although... just to be a prick... I must point that both are, in fact,
deprecated. ;^)

Jim Davis
 
R

Richard Cornford

(However, if we want to get pendantic there is the fun that the MIME
type "text/javascript" itself isn't exactly standardized... it was
ratified and deprecated at the same time... at the moment it's the
same state as the "Language" attribute. ;^) )

The W3C prompted a fiasco in requiring a type attribute, specifying that
it was a MIME type (and referencing the official list of MIME types) and
then citing the (at the time) fictional "text/javascript" as the only
ECMAScript related example. It left us with no reasonable choice but to
use "text/javascript" in the type attribute regardless of its unofficial
status, and the browser manufacturers with little choice but to
disregard HTTP content type headers sent with script files (as there was
no 'correct' MIME type to accept).

And now "text/javascript" has been recognised, deprecated, and "correct"
alternatives provided we cannot stop using "text/javascript" because the
current browsers will have no idea what to make of the new official MIME
types. A situation that is likely to remain for the next 4-5 years.

Still, that particular botch in the HTML specification is not nearly as
bad as the way they rendered the NOSCRIPT element unusable (in part
through failing to provide it with a matching type attribute so it could
be used when a particular type of scripting was unavailable).

On the subject of the deprecation of language as an attribute and
"text/javascript" as a MIME type, these deprecations are in different
standards. The status of the type attribute in not altered by the
deprecation of one if its values and non-deprecated alternatives exist
for its value, even if it will not be practical to use them form many
years.

Ironically, the older browsers that don't really understand the type
attribute and just default to javascript anyway will be more tolerant of
the use of the new MIME types than the browsers that have been in use in
the recent past will be.
1.3 _or higher_ (which as we've already noted can succesfully keep
versions of IE and Opera from biting).

My preference is to maximise active script support across browsers and
so only exclude browsers on the basis of their capabilities. Opera 7 and
IE 5 are both dynamic visual browsers capable of most of what can be
achieved in the other dynamic visual browsers, so I see little reason to
exclude them, and in the event that they cannot support a script I can
find other means of determining that.

I don't like the idea of excluding based on a browser's willingness to
accept a language version. I would worry about not knowing how the
"unknown browser" will react, or eve3n the set of browsers I am aware
of. Of the dynamic visual browsers I would rate Safari/Konqueror as the
least capable, with IceBrowser only fractionally ahead of them. I cannot
be sure of how they (and their various versions) may react to
language="javascript1.5" but I doubt that I want to exclude Opera 7
while including less capable browsers. I prefer to make decisions based
on what a browser is actually capable of.

My gander is raised by those that scream "STANDARDS" and beat their
chests but seemingly have no sympathy for those trying to work in the
real world where there is sloppy support and, in some cases, hacks
being the only method for getting something done.

Standards are very important and useful, and their adoption has
certainly contributed to making my life progressively easier. But I also
dislike the promotion of standard for their own sake, and without a
regard for the realities of the context in which they are used. XHTML
being a particular bugbear of mine when people propose writhing XHTML
because it is "the future", serving it as text/html and then scripting
the resulting HTML DOM. I.E. writing XHTML and then scripting it on the
assumption that the browser will be interpreting it as tag soup HTML.

Probably the most important aspect of standards is to read and
understand the ones that are applicable to a particular context, and to
understand their implications. It is probably the widespread failure of
web developers to ever do that that is most responsible for the
knee-jerk reaction of insisting upon standards no matter what. A
polarisation of attitudes, in which the insistence upon dogmatically
following the standards is almost justified by the monumental stupidity
that follows from the ignorance of them.

I read a good example in the last couple of weeks. A PHP author had
found a 'nice' little script that allowed the conditional serving of
XHTML as text/html or application/xhtml+xml depending on the content of
the HTTP request's Accept header (i.e. an effort at content
negotiation). Unfortunately the author of this script had done so in
total ignorance of the specified mechanism for content negotiation and
had instead decided to just search the content of the Accept header for
the character sequence "application/xhtml+xml" and use that content type
if it was found. The practical upshot being that an Accept header in a
request that explicitly stated its rejection of application/xhtml+xml
would be served that exact content type. And of course the PHP author
who was using the script also had no understanding of HTTP and its
content negotiation mechanism (even though HTTP is pretty much
fundamental to server-side scripting).

So I want people to understand the standards that apply to what they are
doing, and use those standards in preference to not doing so, but I am
also willing to accept that some things are best done outside of
published standards. However, my impression is that there are far fewer
things that actually require a disregard of the published standards than
some of the people who argue in that direction seem to think there are.
That is, if some of the people who cry; "you cannot always follow
standards" enumerated their specific concerns they may find others in a
position to significantly shorten the list. And in the absence of the
specifics I start to suspect that the cry is actually a justification
for sustaining and ignorance of the standards.
Personally I would REALLY like to see the standard expanded
to indicate supported language version.
<snip>

If ECMA 262 3rd edition was the last version of the specification for
the language there would be no need for a language versioning mechanism.

Richard.
 
J

Jim Ley

Yes - all of them. The former can specific version while the latter
cannot - this is a difference.

but only some browsers support versions on the former even, the latter
can also have a version and other consider e4x in Mozilla.
While that's true in a sense it's not in practice. JScript (and other
browser implementations) are ECMAScript complaint - so they happily accept
"JavaScript1.3" (for example) as a language attribute.

ECMAScript compliance has nothing to do with JavaScript1.3 as a
language attribute, indeed IE with JScript 5.6 despite being broadly
ECMAScript Ed.3 compliant which only JavaScript 1.5 does not support
JavaScript1.5 in the language attribute.
The marketing name
of the implementation doesn't affect it compatibility with the standard
name.

JavaScript1.5 is not a standard name!

[JavaScript1.3]
You're code won't run on Netscape 2.0 but neither will you have to deal with
it's broken implementation.

It will however run on other inferior user agents and won't run on
many capable user agents...

Jim.
 
K

Kevin Newman

Lasse said:
I recommend only using the type attribute and using feature detection
for differences between different browsers.

Is there a way to detect for features like try/catch or get/set? Just
having these keywords in your javascript can break the javascript in
some browsers, even if they are not in that browsers code path (so it
breaks during parsing).

Not that I've been able to avoid that problem with the language
attribute ...

Kevin N.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top