Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between "script type" and "script language" declarations

Tags:

javascript

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)

like image 996
amindfv Avatar asked Jan 04 '12 21:01

amindfv


People also ask

What is a script type?

scripttype. Specifies the type of the script. Some common values: A JavaScript MIME type like: application/javascript (default) or application/ecmascript.

What is the meaning of script type text JavaScript?

The HTML <script> type Attribute is used to specify the MIME type of script and identify the content of the Tag. It has a Default value which is “text/javascript”. Syntax: <script type="media_type"> Attribute Values: It contains a single value i.e media_type which specifies the MIME type of script.

What is script type in HTML?

The <script> HTML element is used to embed executable code or data; this is typically used to embed or refer to JavaScript code. The <script> element can also be used with other languages, such as WebGL's GLSL shader programming language and JSON.

What are different types of script tags?

async: It is used to specify the script is executed asynchronously. charset: It is used to specify the character encoding used in an external script file. defer: It is used to specify that the script is executed when the page has finished parsing. src: It is used to specify the URL of an external script file.


2 Answers

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.

like image 181
Matt Ball Avatar answered Sep 20 '22 20:09

Matt Ball


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).

like image 29
Quentin Avatar answered Sep 19 '22 20:09

Quentin