Rules  1  2  3  4  5  6  7  8  9  10  11  12  13  14 
Rule 12 - Remove Duplicate Scripts
 Examples  1  2  3 
Example 1 - Duplicate Scripts - Not Cached

Make sure to view this page in IE to see the duplicated script downloaded twice.

Occasionally, I've seen pages where a single JavaScript file is declared twice. This typically occurs in different locations in the page, but it is essentially the same as this:

<script src="dupe-expiresoff.js"></script>
<script src="dupe-expiresoff.js"></script>

This is bad because the browser ends up executing the JavaScript code twice. In this example, where the JavaScript file is not cacheable, it also results in the browser making two HTTP requests for the script in Internet Explorer.

You'll have to watch the HTTP packets using a packet sniffer, but the number of times the script is executed can be shown here by simply printing out the value of iCounter, which is incremented in the JavaScript file.

stevesouders.com | contact SteveGreyhound, the 2nd fastest land animalThis is the companion website for High Performance Web Sites by Steve Souders.