Welcome to WebmasterWorld Guest from 54.159.2.45

Forum Moderators: open

Message Too Old, No Replies

Proper linking for external JavaScript files

language is out; type is in

     

tedster

4:02 am on Jun 18, 2001 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Apparently this change happened a while back, but I didn't catch it until recently, when I ran a few problem pages through the W3C validator.

When linking to an external .js file, I always used the attribute language="JavaScript" in the script tag. This doesn't validate. The proper attribute is type="text/javascript".

There are sources all over the web that still recommend the language attribute, so I'm not rushing to correct all my sites just now, but seems like that job must be done some day.

(edited by: tedster on 9:20 am (gmt) on June 18, 2001

chiyo

4:38 am on Jun 18, 2001 (gmt 0)

WebmasterWorld Senior Member chiyo is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Thanks Tedster. great advice.. We tend to use public domain js initially and adapt/extend them over the years. and yes hadn't notice that there was 2 ways of referring to js scripts in our code.

Xoc

6:03 am on Jun 18, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should use both attributes. The language attribute is deprecated. The type attribute is the new one. Old browsers don't support the type attribute. A strict html 4.0, or xhtml 1.x page won't validate with the language attribute, but no browser really can do strict html since support for cascading style sheets is so bad.

<edit>Fixed wording</edit>

(edited by: Xoc at 4:17 pm (gmt) on July 14, 2001

Rumbas

8:15 am on Jun 18, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Could you clarify this - I'm a bit slow ;)

This is the linking I've always used:

<script language=JavaScript src="file.js"></script>

Change that to:

<script type="text/javascript" src="file.js"></script>

tedster

9:19 am on Jun 18, 2001 (gmt 0)

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



To accommodate old and current browsers, we should be using:

<script type="text/javascript" language="JavaScript" src="file.js"></script>

Thanks, Xoc.

Rumbas

1:13 pm on Jun 18, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Thanks guys :)