Investigate the relationship between the storage and function of JavaScript tags.

Source: Internet
Author: User

Investigate the relationship between the storage and function of JavaScript tags.

On a webpage, we can place JavaScript code anywhere in an html file, but generally in a head or body tag.

In general, where <script> elements are placed is closely related to their functions. Here we will discuss two situations:

1. Put it in

The <script> element is placed in the head to allow the browser to read from the beginning. The <script> element is loaded and executed at the beginning of the parsing of the entire webpage, its priority is second only to <title> elements.

Then parse the rendering in sequence.

Application: for example, JavaScript code for page display initialization must be placed in the head.

2. In the <body> section

The browser parses the Code in order of page tags. When the JavaScript code is read, the statement is executed.

However, some JS functions are called through events, so the specific location on the page does not affect the time when the function is applied. Therefore, considering the front-end performance problems, you can put the JS Code that is not the first execution and event call at the bottom of the body.

Write and read:

<! Doctype html> 

As you can see above, the storage and function of javascript labels are closely related. I hope this article will help you.

Articles you may be interested in:
  • Location of javascript labels on the page
  • Sample Code for JS Implementation of switching the tab Effect
  • Js: click "a" to highlight the color of the current tag.
  • Js listens to the scroll bar event so that the content of a label is always in the same position.
  • A simple tab with style written in pure css + js
  • Use JS or jQuery to simulate Mouse clicking a tag Event code
  • Js implementation of a label hyperlink to submit form Method

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.