Are there any important differences between declaring <script type="text/javascript"> </script>
and <script language="javascript"> </script>
?
(Note I'm not asking about these declarations vs. the blank "<script>
" tag)
Are there any important differences between declaring <script type="text/javascript"> </script>
and <script language="javascript"> </script>
?
(Note I'm not asking about these declarations vs. the blank "<script>
" tag)
Use <script type="text/javascript">
or simply <script>
(if omitted, the type
is the same). Do not use <script language="JavaScript">
; the language
attribute is deprecated.
The language attribute was used when <script>
was introduced in HTML 3.2 and took a language name (such as JavaScript
). The type attribute replaced it in HTML 4.0 (as everything describing non-HTML media started taking MIME types) and takes a MIME type (such as text/javascript
). More recently it also supports the special value module
for JavaScript modules (which support the import
keyword).
<script language="javascript"> </script>
is deprecated and shouldn't be used anymore.
<script type="text/javascript"> </script>
is the current (HTML4) way to do it.
If you have an HTML5 DOCTYPE, you can just do <script> </script>
.
Language is generally used to indicate the Javascript version that your script requires. Browsers that support the language attribute won't load or run the script if it doesn't support it. About the only use would be if you had critical Javascript functions where you needed workarounds for older browsers.
I think <script language="JavaScript">
not passes validation HTML 4.01. Type attribute is required.