On starting to type <script>
, in HTML syntax, pressing autocomplete causes the following code to appear:
<script type="text/javascript"></script>
However, the type text/javascript
is obsolete. This was used in the early days of Html.
The correct content type to use in browsers is application/javascript
. This helps browsers accept the content as JavaScript code.
HTML script tag completion uses obsolete syntax
fewew62826
#1
0 Likes
jfcherng
#2
Source?
From MDN (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script), I think text/javascript
is good.
0 Likes
deathaxe
#3
The topic is discussed at
While MDN still points to text/javascript
, the linked IETF RFC marks it obsolete and suggests application/javascript
.
I’d just call it another example of standards vs. reality.
1 Like
jfcherng
#4
Interesting that RFC is published in 2006…
But at the same time from the same SO answer:
So the bottom line is that the type=“text/javascript” doesn’t do anything as far as the javascript is concerned, but it’s part of the spec for both HTML 4 and XHTML 1.0 .
There seems to be no point to use application/javascript
nowadays as
- if we want to support HTML 4 browser, then
text/javascript
. - if we want to support HTML 5 browser, then no
type
is needed. (see the same MDN link)
1 Like