abson
abson

Reputation: 9358

external script usage in javascript

Can i use external script only with .js extensions? Can't i use it when using the extension as .htm?

Upvotes: 2

Views: 175

Answers (3)

qwertymk
qwertymk

Reputation: 35344

Most jsonp is done with an external php file. Even YQL doesn't use the js extension. So yes you are able to and in fact most people do.

Upvotes: 0

anddoutoi
anddoutoi

Reputation: 10111

Theoretically the extension is not important, it´s the MIME type the server serves the resource that´s important.

In practice there has existed issues with UAs from vendors (IE) that has been file extension maniacs.

Another issue is if you serve the page from the file-protocol.

So my advice, stick with .js

Upvotes: 0

Marcel Korpel
Marcel Korpel

Reputation: 21763

You can. What matters is the MIME type with which the script is served (by the server). It should be

application/javascript

or

application/x-javascript

This is used by certain PHP scripts that have the .php extension, but actually serve JavaScript (not that I like this, but it's possible).

Upvotes: 2

Related Questions