Adding defer = "Defer" to JS scripts in HTML

Source: Internet
Author: User

Previously, scripts introduced on the page were directly written in the head label.

<SCRIPT type = "text/JavaScript" Language = "JavaScript" src = "test. js"> </SCRIPT>

I have never added the defer attribute to the script tag.

Today, we can see that someone is using this label. It is quite useful to check it from Baidu,It means loading the introduced JS script after the labels in the page are loaded.,

However, defer also has drawbacks. The script introduced after the <SCRIPT> label cannot write document. Write (), becauseDirectly output the results. Also, the script that is executed immediately cannot be added to defer = "Defer" (but the default defer is false, and the default attribute can be added );

What's even worse isFirefox does not support this Script Attribute. Chrome should support this attribute. However, unlike IE, Chrome does not execute two scripts in chrome. The following scripts borrow the preceding script, the following may be executed first, but it is not loaded yet. 

It was very depressing and I was so happy that I finally felt the most stupid way:Place the JS script at the bottom of the page.

If there is any better way to use a single position, please share it. If there is anything wrong with my writing, please point it out. Thank you !!!

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.