Difference between these two things

I have a doubt about writing this statement below

  • <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"/>

  • <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"/>

I did not mention the type in the second statement here. But still I get jquery or the $ character. Can anyone explain to me?

Here I am using VS 2010.

+4
source share
4 answers

The first indicates explicitly the MIME type. Your browser can read the file as Javascript by default. But doing this may be wrong. Especially in browsers that support multiple scripting languages ​​for ex vbscript.

MIME_type - Some values:

 text/javascript text/ecmascript application/ecmascript application/javascript text/vbscript 

Note. According to IANA, the "Text Type / javascript" MIME is deprecated. New standard "Application / JavaScript". However, "application / javascript" is not supported by Internet Explorer.

http://www.w3schools.com/tags/att_script_type.asp

0
source

Browsers have for many years assumed that the script will be JavaScript unless the type attribute says otherwise. The HTML5 project makes this explicit.

Note that using XML-style self-closing tags:

  • OK in XHTML 1.0 / 1.1 (but leave the type attribute disabled)
  • NOT OK in HTML compliant XHTML 1.0 (which you need to use if you want IE8 and below to work)
  • NOT OK in HTML 4.01
  • NOT OK in HTML5

If you are writing HTML 4.01 (which is a reasonable idea for most sites, as it has mature QA tools), then you should write:

 <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"> </script> 

If you are writing XHTML 1.0 and jumping through the hoops necessary to deliver it to Internet Explorer 8 and below, you should use the same syntax for script elements as HTML 4.01.

If you are writing HTML5, you can omit the type attribute, but an explicit end tag is still required.

+7
source

The browser will try to see what a "type" or "language" script is. But the first one is the best.

+1
source

If the type attribute is not specified in the script tag, the default value of the type is "text / javascript" for the HTML 5 specification.

By Client JavaScript

0
source

Source: https://habr.com/ru/post/1334925/


All Articles