flash service

High_Performance_Web_Sites

Issue link: https://read.uberflip.com/i/1146286

Contents of this Issue

Navigation

Page 108 of 169

Avoiding Duplicate Scripts | 87 In addition to generating unnecessary HTTP requests in Internet Explorer, time is wasted evaluating the script multiple times. This redundant JavaScript execution happens in both Firefox and Internet Explorer, regardless of whether the script is cacheable. In the previous examples, the duplicated script increments a counter that is displayed in the page. Because the script is included twice and evaluated twice, the value of the counter is 2. The problem of superfluous downloads and evaluations occurs for each additional instance of a script in the page. In the following example, the same script is included 10 times, which results in 10 evaluations. When you reload the page, 10 HTTP requests are made (only in Internet Explorer). Duplicate Scripts—10 Cached http://stevesouders.com/hpws/dupe-scripts-cached10.php To summarize: • Including the same script multiple times in a page makes it slower. • In Internet Explorer, extra HTTP requests are made if the script is not cacheable or when the page is reloaded. • In both Firefox and Internet Explorer, the script is evaluated multiple times. Avoiding Duplicate Scripts One way to avoid accidentally including the same script twice is to implement a script management module in your templating system. The typical way to include a script is to use the SCRIPT tag in your HTML page: An alternative in PHP would be to create a function called insertScript: While we're tackling the duplicate script issue, we'll add functionality to handle dependencies and versioning of scripts. A simple implementation of insertScript follows:

Articles in this issue

Links on this page

Archives of this issue

view archives of flash service - High_Performance_Web_Sites