Is JavaScript is Slowing Down the Web?
There’s an interesting article over on readwriteweb.com discussing the problems with JavaScript and how it can generally slow down a web page.
The author correctly points out that JavaScript is a single threaded language that halts the execution of anything else as it does it’s things. This means that when you include in-line JavaScript code such as the author’s Twitter example, the more you include the slower things get.
To solve the problem, the author suggests:
- Deferring the execution of JavaScript until after the page loads
- Minimizing the amount of code that runs on load
- Load balancing requests using different URLs
- Use standard libraries
- and lastly, use common sense.
First, I’l stress that inline JavaScript is a bad idea altogether and that of the author’s suggestions, I can’t agree more with the first and second. I discuss using the load event to invoke your scripts extensively throughout my book and I’m sure you’ve heard about it elsewhere on the web as well. After changing your thinking you’ll look back on the mess of code you once wrote and say “What was I thinking?”
The third item, load balancing, I don’t think will help you out much. It would affect the performance of your system in high traffic but it’s not going to do anything to speed up the client’s browser. Really, the same logic applies to any files you have, the more files you need to download the more files will be requested from your server. You can use techniques such as CSS sprites for images and just combine everything into one file to reduce JavaScript or CSS requests. Check out the ySlow plugin for Firefox/Firebug for more.
The forth item, standard libraries, I’d caution you on. I agree that standard libraries are good but make sure you know what’s going on. Don’t assume a library is good just because someone else wrote it and others are using it. As I discuss in my book, there are a number of this you need to take into consideration when selecting a library including:
- Does it have all the features you’re looking for?
- Does it have more features than you need?
- Is it modular?
- Is it well supported by a community of developers?
- Does it have documentation?
Lastly using common sense is obvious. The author focuses on “widgets” but in general, remember your best practices and standards and you’ll probably be fine.
Don’t forget to read the original article: How JavaScript is Slowing Down the Web (And What To Do About It)
0 Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URI


