The script tag in JS

Source: Internet
Author: User

Using the script tag in the page to introduce JavaScript file (<script type= "Text/javascript" src= "JS file Address" ></script>), when the browser renders the page, When a SCRIPT element is read, the browser does not process its contents in HTML or XHTML, and the browser notifies the browser's scripting engine to take over the contents of the script element.

the Type property of the script element defines the scripting type, which is type:

1.text/ecmascript (means parsing this script in ECMAScript manner, which is based on the ECMA-262 scripting standard)

2.text/jscript (which is a variant of the ECMAScript language implemented by Microsoft in IE), which means parsing the script in JScript mode

3.text/vbscript

4.text/vbs

(3, 4 representations are handled in the form of Microsoft VBScript, which is a completely different scripting language)

the Language property of the script element (the previous script tag uses its properties to resolve browser compatibility issues):

<script type= "Text/javascript" src= "A.js" language= "javascript1.2" ></script>

Language defines the browser version that supports the script (that is, the code in the A.js file is executed if the browser supports javascript1.2)

The defer property of the SCRIPT element:

<script type= "Text/javascript" src= "A.js" language= "javascript1.2" defer= "defer" ></script>

The Defer property is set to "defer", which means that the script does not generate any document content, so the browser can process the rest of the page ahead of time, processing the script part when the page is finished and ready to display.

Where the script tag is placed in the page.

There is a limit to the amount of resources loaded by the browser from the same domain name, so when you add a script to the head element, the first load will be a script, followed by the remainder of the document. Why is it that putting the SCRIPT element tag with the introduction of JavaScript in the head may cause the browser to delay the display of the rest of the page? The main reason is that the document.write method may be called in the script to modify the Dcument object.

Location reference for JavaScript script Storage learning address: http://www.cnblogs.com/ddyq/archive/2012/03/06/2382816.html

Reference: the JavaScript Learning Guide

(To be perfected)

The script tag in JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.