To explore the relationship between the storage of JavaScript label location and function _javascript skill

Source: Internet
Author: User

In a Web page, we can place JavaScript code anywhere in the HTML file, but generally in the head or body tag.

In general, where the,<script> elements are closely related to their functional role, here are 2 things to discuss:

1, put in

The <script> element is placed in the head in order for the browser to read the,<script> element in the first place, which will load execution when the entire page is first parsed, after the <title> element.

Then parse the rendering down in turn.

Applications: For example, the initialization of the page display JS must be placed in the head inside.

2, put in <body> part

The browser parses in the order of the page labels and executes the statement when it reads to the JavaScript code.

But some JS function is called through the event, so the specific place in the page which does not affect the role of the time, so, in consideration of the front-end performance problems, you can not be the first to execute and event calls JS code placed in the bottom of the body.

Write a look:

<! DOCTYPE html>
 
 

As noted above, JavaScript label location is closely related to function, I hope this article is helpful to everyone.

Related Article

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.