Solved

Javascript *.js mime type

Posted on 1998-09-28
5
599 Views
Last Modified: 2008-02-26
i have just included javascript source in a separate file instead of embedding in the HTML document.:-

<SCRIPT SRC="anexample.js">
</SCRIPT>
_________________________________________
according to a netscape javascript manual i must map the .js suffix to the MIME type "application/x-javascript" otherwise navigator improperly loads the javascript.... ..

But i have NOT done the mapping (I have checked all the diff. mime type and have not found a .js entry on the server) and it still works when i request the above HTML document i.e. the javascript src works!

what gives?
0
Comment
Question by:eriklee
  • 2
  • 2
5 Comments
 

Expert Comment

by:javaman17
ID: 1271571
Put this in it too
<SCRIPT LANGUAGE="JavaScript" Src=="anexample.js">
0
 

Author Comment

by:eriklee
ID: 1271572
so Javaman, why does it work?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 1271573
eriklee: The newer browsers makes an effort to figure out the contents from the suffix. If you change the name to .myjs and map that to application/x-javascript it will only work while the mapping is in effect.
Also if the src was pointing to a cgi, the cgi could output the
Content-type: application/x-javascript HTTP header and you would also be fine.

javaman17: You do not answer the question (did you read it?) and you add to the confusion with a typo...

Michel
0
 

Author Comment

by:eriklee
ID: 1271574
hi Michel,
thanks for your insight. Interesting. I tested based on your theory about the newer browser checking out the conttent of the SRC='files'  (i think the older ones will falter).

Using Netscape4.05  after i changed the xyz.js to xyz.jsx and it still works without having to use mappings at all - the mime-type mapping just doesn't play a part at all.

Now would u like to report your reply as an answer
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 50 total points
ID: 1271575
The newer browsers makes an effort to figure out the contents from the suffix.
Older ones (also depending on server) needs the mime mapping at server level.

If you change the name to .myjs and map that to application/x-javascript it should only work while the mapping is in effect. It seems however that Netscape will accept any extention in the src. This has not been verified except by you.

If the src was pointing to a cgi, the cgi could output the Content-type: application/x-javascript HTTP header and you would also be fine.

There appear to be an intermittent bug in NS 4.05 that sometimes shows the source instead of parsing it. A reload fixes it.

Netscape 3 will parse any JS1.2 in a script file, giving errors if the javascript keyword in not recognised. The workaround is putting js1.2 inline.

This is more or less the story on JS src files

Michel
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now