Example of script merge to improve javascript Performance

Source: Internet
Author: User

Example of script merge to improve javascript Performance

Script merge can effectively improve javascript performance. The following is a good example.

When each <script> tag is initially downloaded, page rendering is blocked. Therefore, reducing the number of <script> tags contained in the page helps improve this situation. This is not only for external link scripts, but also for the number of embedded scripts. Each <script> tag that the browser encounters during parsing an HTML page may cause a certain latency due to script execution. Therefore, minimizing the latency will significantly improve the overall performance of the page.

 

Generally, a large website or network application depends on several javascript files. You can merge multiple files into one, so that you only need to reference one <script> tag to reduce performance consumption. File merging can be performed using an offline packaging tool or similar to YaHoo! Combo handle real-time online service.

The Code is as follows:

<! -- Before optimization: -->

<Html>

<Head>

<Title> Script Example </title>

</Head>

<Body>

<P> Hello world! </P>

<Script type = "http://yui.yahooapis.com/combo? 2.7.0/build/yahoo/yahoo-min.js "> </script>

<Script type = "http://yui.yahooapis.com/combo? 2.7.0/build/event/event-min.js "> </script>

</Body>

</Html>

 

<! -- After optimization: -->

<Html>

<Head>

<Title> Script Example </title>

</Head>

<Body>

<P> Hello world! </P>

<Script src = "http://yui.yahooapis.com/combo? 2.7.0/build/yahoo/yahoo-min.js & 2.7.0/build/event/event-min.js "type =" text/javascript "> </script>

</Body>

</Html>

 

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.