• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

4. Variables, Functions, and Flow Control > 4.8. Improving Script Performance

Improving Script Performance

NN 2, IE 3

Problem

You want to speed up a sluggish script.

Solution

When swallowing small doses of code, JavaScript interpreters tend to process data speedily. But if you throw a ton of complex and deeply nested code at a browser, you may notice some latency, even if all the data is downloaded in the browser.

Here are a handful of useful tips to help you unclog potential processing bottlenecks in your code:

  • Avoid using the eval( ) function

  • Avoid the with construction

  • Minimize repetitive expression evaluation

  • Use simulated hash tables for lookups in large arrays of objects

  • Avoid multiple document.write( ) method calls

Look for these culprits especially inside loops, where delays become magnified.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint