|
Your JavaScript can definitely affect the loading of your webpage and in several ways.
Every separate file that your page needs to load counts as an HTTP request, and that includes JavaScript, CSS, images, Flash, etc. The more requests you have, the longer it will take for the page to load. If a file does not originate on the same server as the page, it could take additional time to load because another server will need to be connected to in addition to your server.
The placement of JavaScript on your page may also affect the loading and rendering of other elements of your page. JavaScript acts as a blocking script, meaning that it will block other files from being loaded until it has finished. Older browsers will allow one or two simultaneous download, modern browsers will allow 6-8. If you have two or more JavaScript files in a row, they will block everything that comes after them in the code until they have been loaded for older browsers.
If you depend on JavaScript to render any part of your layout, your browser will not do it until that particular file has loaded and the proper browser event has been triggered.
Finally, if you're using any sort of framework like jQuery, MooTools, Prototype, etc., your JavaScript files have a tendency to be very large, which can significantly affect the page load time.
Solutions to these problems are fairly easy. First, minimize the number of HTTP requests by combining your CSS and JavaScript files. You won't be able to do that with your ad code, but you should be able to do it with the rest. Second, minify your JavaScript files. Third, Enable GZIP compression for your HTML, CSS, and JavaScript files. This can decrease your page load size by up to 80%. Fourth, compress your images and use CSS sprites where possible. There aren't too many layouts that couldn't be achieved with only 3-4 images if you're using sprites. Fifth, put your JavaScript files toward the bottom of your page code if at all possible. Sixth, use a lazy loading script to defer the loading of images below the fold.
I've found Firebug and YSlow (both plugins for Firefox) to be extremely helpful in this. I hope that helps answer your question. The YSlow blog in particular has some great resources for minimize page loading time, even more than I mentioned here.
|