Remove Duplicate Scripts
How removing Duplicate Scripts improves Web site download performance
It hurts performance to include the same JavaScript file twice in one page. This isn't as unusual as you
might think. A review of the ten top U.S. web sites shows that two of them contain a duplicated script.
Two main factors increase the odds of a script being duplicated in a single web page: team size and
number of scripts. When it does happen, duplicate scripts hurt performance by creating unnecessary
HTTP requests and wasted JavaScript execution.
Unnecessary HTTP requests happen in Internet Explorer, but not in Firefox. In Internet Explorer, if an
external script is included twice and is not cacheable, it generates two HTTP requests during page
loading. Even if the script is cacheable, extra HTTP requests occur when the user reloads the page.
In addition to generating wasteful HTTP requests, 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.
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.
<script type="text/javascript" src="menu_1.0.17.js"></script>
An alternative in PHP would be to create a function called insertScript.
<?php insertScript("menu.js") ?>
In addition to preventing the same script from being inserted multiple times, this function could handle
other issues with scripts, such as dependency checking and adding version numbers to script filenames
to support far future Expires headers.
Other Topics
Overview Web Site performance Improvement
Minimize HTTP Requests
Use a Content Delivery Network
Add an Expires or a Cache-Control Header
Gzip Components
Put Stylesheets at the Top
Put Scripts at the Bottom
Avoid CSS Expressions
Make JavaScript and CSS External
Reduce DNS Lookups
Minify JavaScript and CSS
Avoid Redirects.
Remove Duplicate Scripts
Configure ETags
Make Ajax Cacheable
Flush the Buffer Early
Use GET for AJAX Requests
Post-load Components
Preload Components
Reduce DOM Elements
Split Components Across Domains
Minimize the Number of iframes
No 404s
Reduce Cookie Size
Use Cookie-free Domains for Components
Minimize DOM Access
Develop Smart Event Handlers
Choose over @import
Avoid Filters
Optimize Images
Optimize CSS Sprites
Don't Scale Images in HTML
Make favicon.ico Small and Cacheable
Keep Components under 25K
Pack Components into a Multipart Document
Avoid Empty Image src