Redo JS Virtuoso First play: script and JS load

Source: Internet
Author: User

 

No matter what JS is packaged into, and ultimately to the browser to execute the JS are the original, are inseparable from the principle of native JS.

Script tag in HTML to load JS tags, we know that JS can be from the external, local, or internal section of the code, here only to discuss from the external loading, for a web-based data exchange at any time the browser, network requests must be executed asynchronously, The natural JS file generally good asynchronous execution, not easy to cause the UI, but the script tag default loading JS is synchronous, blocking, that is, by default the browser according to the way from top to bottom, from left to right to interpret the execution script, For the synchronization request JS file will cause the JS file download complete before actually rendering the UI, this is very easy to understand. Improve the Web user experience?

1 asynchronously download the JS file, where you can use async inside the script tag to indicate that the file was downloaded asynchronously: <script src= "Xxx.js" async>

2 lazy loading, where the defer keyword is used to indicate that the entire document HTML element is loaded before it starts to download the JS file, but this does not mean that it must occur before or after the document Load event, <script src= "Xxx.js" DEFER> If there are multiple such JS delays loading their

The order is also uncertain, so generally defer used less

3 UI loading complete start loading JS, here is very simple, directly <script src= "Xxx.js" > put to the end of the document can be

Knowledge Points: synchronous, asynchronous

Redo JS Virtuoso First play: script and JS load

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.