external script usage in javascript
Can i开发者_JS百科 use external script only with .js extensions? Can't i use it when using the extension as .htm?
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).
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
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.
精彩评论