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>