CS193H: High Performance Web Sites Lecture 15: Rule 12 – Remove Duplicate Scripts Steve Souders Google
announcements
Duplicate Scripts hurts performance extra HTTP requests if not cacheable IE and FF extra executions all browsers atypical? happens with ads adsonar.js (6K) loaded six times happens with iframes fc-os-ext.js (15K), gadgets_en.js (155K) each loaded 3 times
Script Insertion Functions <?php function insertScript($jsfile) { if ( alreadyInserted($jsfile) ) { return; } pushInserted($jsfile); if ( hasDependencies($jsfile) ) { $dependencies = getDependencies($jsfile); for ( $i = 0; $i < count($dependencies); $i++ ) { insertScript($dependencies[$i]); } echo '<script type="text/javascript" src="'. getVersion($jsfile). '"> "; } ?>
Web 100 Profile project Aravind and I added 4 columns to compare double checks: delta YSlow = YSlow1 – YSlow2 delta %age time = ( (backend1/total1) – (backend2/total2) ) delta # requests % = ( (requests1 – requests2)/requests1 ) delta total size % = ( (size1 – size2)/size1 ) goals: <10 & <20% & <10% & <20% ~half of the sites had deltas bigger than this
Homework 11/7 11:59pm – rules 4-10 applied to your "Improving a Top Site" class project 11/12 3:15pm – Web 100 Double Check look at your rows in Web 100 spreadsheet double-check your entries for any rows in red update incorrect entries enter "y" in "Double Checked" column
Questions What are two typical causes of duplicate scripts? In what way(s) can duplicate scripts be bad for performance?