Peter Michaux wrote:
Richard Cornford wrote:
>Peter Michaux wrote:
<snip>
<script src="path/to/myScript.js" type="text/javascript">
</script>
Although I hear from Douglas Crockford the type attribute
is not necessary
The TYPE attribute is required in formally valid HTML That is;
without a TYPE attribute it will not be possible to get an HTML 4
validator to confirm the document as valid.
I just tested the w3c validator and of course you are correct.
I am glad I didn't state it as fact.
But it is a fact, both specifically (assuming your hearsay report of
what Douglas said is accurate) and generally: it is not necessary to
include a TYPE attribute in a SCRIPT opening tag. It is just also true
that it is not possible to omit the TYPE attribute and create a formally
valid HTML document. Neither excludes the other because they speak of
different things.
Perhaps I've learned that all JavaScript related
information really does have to be verified.
That will do you no harm.
<snip>
>>in favor of the MIME type the server
sends with the actual file.
<snip>
That is completely untrue. A number of years ago I
experimented with sending diverse MIME types in
content-type headers with javascript files and found
no evidence that any browsers of the time paid any
attention to the value used.
Very interesting. Thanks for the info. I wonder if things
have changed in the last few years.
A very significant change happened this year, in that official MIME
types for javascript were introduced (after an absence of 10 years,
which seems to explain why browsers were not interested in what MIME
type appeared in content type headers).
Either way, it doesn't really matter because I
would like my documents to validate and I imagine
including the type attribute can only act as a safety
net.
It is probably also a very good idea to send an appropriate MIME type in
content-type headers along with imported javascript. They may be ignored
at present but now there are official values the likelihood is that the
future will see browsers that take notice of them. And anyway, doing the
whole job, in sending content over HTTP to a client, isn't finished
until you are sending appropriate HTTP (including content-type) headers
with everything. Leaving it to a blend of random chance and the default
configuration of servers is just not professional.
Richard.