Issue link: https://read.uberflip.com/i/1146286
86 | Chapter 12: Rule 12: Remove Duplicate Scripts Duplicate Scripts Hurt Performance There are two ways that duplicate scripts hurt performance: unnecessary HTTP requests and wasted JavaScript execution. Unnecessary HTTP requests happen in Internet Explorer, but not in Firefox. In Inter- net Explorer, if an external script is included twice and is not cacheable, the browser generates two HTTP requests during page loading. This is demonstrated in the "Duplicate Scripts—Not Cached" example. Duplicate Scripts—Not Cached http://stevesouders.com/hpws/dupe-scripts.php This won't be an issue for people who follow the advice in Chapter 3 and add a far future Expires header to their scripts, but if they don't, and they make the mistake of including the script twice, the user has to endure an extra HTTP request. Chapter 6 explains how downloading scripts has an especially negative impact on response times. Subjecting the user to an extra HTTP request for a script doubles that nega- tive impact. Even if the script is cacheable, extra HTTP requests occur when the user reloads the page. The following example includes scripts that are cacheable. Duplicate Scripts—Cached http://stevesouders.com/hpws/dupe-scripts-cached.php Load this page once to fill the cache, and then click the "Example 2 – Duplicate Scripts – Cached" link to load it again. Since the script is cached, no HTTP requests are made for the script, but if you click the browser's Refresh button, two HTTP requests are made. Specifically, two conditional GET requests are made. For more information, see the section "Conditional GET Requests" in Chapter B. Table 12-1. Number of scripts and stylesheets for 10 top sites Web site Scripts Stylesheets http://www.amazon.com 3 1 http://www.aol.com 18 1 http://www.cnn.com 11 2 http://www.bay.com 7 2 http://froogle.google.com 1 1 http://www.msn.com 9 1 http://www.myspace.com 2 2 http://www.wikipedia.org 3 1 http://www.yahoo.com 4 1 http://www.youtube.com 7 3

