flash service

High_Performance_Web_Sites

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

Contents of this Issue

Navigation

Page 71 of 169

50 | Chapter 6: Rule 6: Put Scripts at the Bottom Scripts at the Bottom http://stevesouders.com/hpws/js-bottom.php The benefit is really highlighted by viewing the pages with scripts at the top versus scripts at the bottom side-by-side. You can see this in the following example. Scripts Top vs. Bottom http://stevesouders.com/hpws/move-scripts.php Putting It in Perspective These examples use a script that takes 10 seconds to download. Hopefully, the delay isn't as long for any scripts you use, but it is possible for a script to take longer than expected and for the user's bandwidth to affect the response time of a script. The effect that scripts have on your pages might be less than shown here, but it could still be noticeable. Having multiple scripts in your page compounds the problem. In some situations, it's not easy to move scripts to the bottom. If, for example, the script uses document.write to insert part of the page's content, it can't be moved lower in the page. There might also be scoping issues. In many cases, there are ways to work around these situations. An alternative suggestion that comes up often is to use deferred scripts. The DEFER attribute indicates that the script does not contain document.write, and is a clue to browsers that they can continue rendering. You can see this in the following example. Deferred Scripts http://stevesouders.com/hpws/js-defer.php Unfortunately, in Firefox, even deferred scripts block rendering and parallel down- loads. In Internet Explorer, components lower in the page are downloaded slightly later. If a script can be deferred, it can also be moved to the bottom of the page. That's the best thing to do to speed up your web pages. Figure 6-6. Scripts at the bottom have the least impact Move scripts to the bottom of the page. html component component component component script

Articles in this issue

Links on this page

Archives of this issue

view archives of flash service - High_Performance_Web_Sites