#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    My room
    Posts
    3
    Rep Power
    0

    MIME type for a Javascript file.


    I have a piece of dynamic text I wish to generate using a script, and then include on various websites using Javascript, like this:
    Code:
    <script language="JavaScript" src="http://www.mydomain.com/cgi-bin/include.cgi"></script>
    I realise for this to work, I need to output the correct content header for the file. I've searched around the net, and there seems to be 2 options for the MIME type:

    application/x-javascript
    or
    text/javascript

    If anyone knows any more details about this, or which would be the best to use, it would be much appreciated.

    -Tim.
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    9
    Rep Power
    0

    RE: MIME type for a Javascript file.


    text/javascript works, but with either, the file is NOT executed in IE/NS if typical security settings are in place.
    I don't know if this is what you want but, if you set the MIME type, the file will be downloaded, not opened.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2001
    Posts
    765
    Rep Power
    13
    You're referring to two different things - HTML code and the server configuration. External .js files should be served as application/x-javascript, and most commercial hosts are configured to do so. The HTML code to call an external .js file, on the other hand, can be written to include either the current type attribute (type="text/javascript") or both 'type' and the deprecated language attribute (language="JavaScript"). If you're using a DTD of [HTML 4.0/HTML 4.01/XHTML 1.0] STRICT, the 'language' attribute won't validate - but, leave it out, and user agents that don't recognize 'type' will expect the older default (JS 1.0). Most people seem to stick with both (or 'language') at this point in time.

    http://www.htmlhelp.com/reference/ht...al/script.html
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    My room
    Posts
    3
    Rep Power
    0
    Originally posted by mrrichardfeder
    External .js files should be served as application/x-javascript, and most commercial hosts are configured to do so.
    That's what I needed to know. Thanks

IMN logo majestic logo threadwatch logo seochat tools logo