Forum Moderators: open

Message Too Old, No Replies

Correct mime declaration for external JavaScript files?

         

JAB Creations

1:24 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Which is it? I've been using the later as long as I can remember but I've read about the first one and I'm not sure what to think.

<script src="1.js" type="application/x-javascript">

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

John

Robin_reala

1:53 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RFC 4329 says:

Use of the "text" top-level type for this kind of content is known to be problematic. This document thus defines text/javascript and text/ ecmascript but marks them as "obsolete". Use of experimental and unregistered media types, as listed in part above, is discouraged.
The media types,

* application/javascript
* application/ecmascript

which are also defined in this document, are intended for common use and should be used instead.

As for compatibility, I've no idea.

Bernard Marx

2:10 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would be very careful indeed when playing with the tried and tested.
As I've said before, validators live in ivory cyber-towers, whilst real-world priorities live in browsers.

If a browser sees a script tag with language or type declaration that it doesn't understand it simply ignores the script entirely. A script tag is better off with no type attribute at all than with a bad one.

type="application/javascript"
type="application/x-javascript"
type="application/ecmascript"

Internet Explorer 6 does not recognise these type values.

...need I say more?

Robin_reala

2:31 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, John did ask for the 'correct' media type :)

But yeah, I always use text/javascript purely on a compatibility point of view.

Bernard Marx

2:36 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No criticism intended, Robin.
:)

JAB Creations

4:49 am on Mar 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So type="application/x-javascript" would be the correct mime for an external JavaScript file?

I won't be working in the job field until IE6 is an unfresh corpose like Netscape 4 is right now anyway so IE7 would be of some concern.

In this case I'd like to bug Microsoft to support the correct mime, just a confirmation to my specific question would be nice before I do so of course! :)

Thanks to you both!

John

Robin_reala

12:46 pm on Mar 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're not going to be getting a job for another 10 years? Wow ;)

JAB Creations

5:22 pm on Mar 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



IoI...don't want to lock myself at a lower level then I'm capable of!

Though I certainly hope IE6 isn't around for TEN YEARS! *croaks*

John

JAB Creations

8:44 pm on Mar 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script src="" type="application/x-javascript">

I'm going with that...confirmed via Opera.

John

Rambo Tribble

1:50 am on Mar 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MSDN suggests that IE doesn't actually recognize any JavaScript related MIME type: [msdn.microsoft.com...]

On the other hand, application/x-javascript is the MIME type that IIS associates with a .js file: [microsoft.com...]

Perhaps the "Internet Explorer Resource Kit" would offer some illumination, but I don't have it, myself.