Jump to content

Optimize JavaScript to Speed Up Web Pages

  simonstl's Photo
Posted Oct 29 2009 04:58 PM

After replacing as much Javascript as possible with CSS and server-side techniques, optimize any remaining Javascript to minimize file size. You can use abbreviated object, variable, and function names to shave bytes. You can automate the process by using a tool such as w3compiler to automatically abbreviate and whitespace-optimize your scripts.

Beyond minifying Javascript, you can often refactor or rewrite procedures with less code to accomplish the same thing (see http://www.refactoring.com). Remember to measure first, then optimize. You can use a Javascript profiler to locate performance bottlenecks. Mozilla's Venkman Javascript Debugger can profile Javascript code.

Loop optimizations such as unwinding can also help you to gain some cycles to increase your Javascript execution speed. Often, built-in functions perform faster than hand-crafted code. For advice on increasing execution speed and minifying Javascript, read Chapter 8, Ajax Optimization, of Website Optimization. Finally, combine and compress external Javascript files to save HTTP requests and bandwidth where possible.

Website Optimization

Learn more about this topic from Website Optimization.

Is your site easy to find, simple to navigate, and enticing enough to convert prospects into buyers? Website Optimization shows you how. It reveals a comprehensive set of techniques to improve your site's performance by boosting search engine visibility for more traffic, increasing conversion rates to maximize leads and profits, revving up site speed to retain users, and measuring your site's effectiveness (before and after these changes) with best-practice metrics and tools.

See what you'll learn

0 Subscribe

0 Replies