Tech Support Websites

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 5 April 2012

JavaScript Performance tips

Posted on 19:15 by Unknown
Excerpted from "Chapter 7: Writing Efficient JavaScript" of the book "Even Faster Websites":
  • Performance .. is not just about how long it takes for the page to load, but also about how it responds as it’s being used.
  • Out-of-scope variables take longer to access than local variables.
  • A very common mistake that leads to performance issues is to omit the var keyword when assigning a variable’s value for the first time. 
  • If an array item or object property is used more than once, store it in a local variable to speed up access to the value.
  • Generally speaking, interacting with DOM objects is always more expensive than interacting with non-DOM objects.
  • The if statement is best used with a small number of discrete values or a range of values; the switch statement is best used when there are between 3 and 10 discrete values to test for; array lookup is most efficient for a larger number of discrete values.
  • To make a loop the most efficient, reverse the order in which you process the items so that the control condition compares the iterator to zero.
  • Trimming strings may be expensive, depending on the size of the string. 
  • Steven Levithan's optimized string trimming function:
    function trim(text){
    text = text.replace(/^\s+/, "");
    for (var i = text.length - 1; i >= 0; i--) {
    if (/\S/.test(text.charAt(i))) {
    text = text.substring(0, i + 1);
    break;
    }
    }
    return text;
    }
  • Array processing is one of the most frequent causes of long-running scripts.
  • Generally speaking, no single continuous script execution should take longer than 100 milliseconds...
  • Because JavaScript is a single-threaded language, only one script can be run at a time per window or tab.
  • Exactly what causes the browser to display the long-running script dialog varies depending on the vendor:
    • Internet Explorer displays it when 5 million (by default) statements have been executed. 
    • Firefox shows it when a script takes longer than 10 seconds (default).
    • Safari displays it when the execution time exceeds default timeout of five seconds
    • Chrome (as of version 1.0) has no set limit on how long JavaScript is allowed to run. The process will crash when it has run out of memory.
    • Opera is the only browser that doesn’t protect against long-running scripts. Scripts are allowed to continue until execution is complete
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Javascript | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Windows 8 keyboard shortcuts
    Win + X   - context menu to access common features like Control Panel, Task Manager, File Explorer, Programs & Features, Run, Search etc...
  • My 30-day personal project - watch 100 hours of Pluralsight videos
    Inspired by Matt Cutts' 30-day challenges , I plan to watch 100 hours of Pluralsight online videos to get up-to-date with current ...
  • Archive tweets & favorites with Google Reader
    There are numerous ways to archive tweets but rather than use yet another tool, I prefer using Google Reader to preserve the tweets I mark ...
  • Azure in Pictures - overview of Windows Azure Features, Services and Common Uses
    Download the Windows Azure Poster in PDF format (1.1MB)
  • What is the difference between Browser Mode & Document Mode in IE
    If you're a web developer and your job actively involves building web pages that work the same in all browsers including the last three ...
  • 10 ways to make laptop battery last longer
    Paraphrased from a Right Choice magazine article with my own opinions: Keep the brightness of the screen as low as possible. If portability ...
  • Dashboard-like info with Browser tabs, Windows 7 Taskbar tabs
    Browser tabs & Windows 7 Taskbar tabs are turning self-aware.  This is how my browser looked the other day: I had the summary of all tha...
  • India ranks fourth in Internet usage
    Deepak Shenoy informs that as per Telecom Regulatory Authority of India (TRAI) data, India has nearly 10 million Broadband connections in ...
  • What's common between Kovid Goyal & Antony Lewis?
    Kovid Goyal Antony Lewis They are both PhDs in Physics and creators of free software applications that have been downloaded by millions. Kov...
  • HOW TO let Google watch over your web activity
    When we get onto the Internet, we trade our privacy for convenience. Everyone from marketers, ISPs to Governments can watch our activities o...

Categories

  • AJAX
  • Android
  • APIs
  • App
  • ASP
  • ASP.NET
  • ASP.NET-MVC
  • Azure
  • Azure SQL Database
  • AzureInPictures
  • Bing
  • Book Review
  • Bookmarklet
  • Browsers
  • C#
  • chart
  • Chrome
  • Cloud
  • CSS
  • CSS3
  • DidYouKnow
  • E-Commerce
  • Excel
  • FB
  • Fiddler
  • Firefox
  • Gadgets
  • GeoLocation
  • GMail
  • Google
  • Google Docs
  • Google Reader
  • Health
  • Hotmail
  • HOWTO
  • HTML
  • HTML/CSS
  • HTML5
  • Humor
  • Hyderabad
  • IE
  • IIS
  • India
  • Internet
  • IT
  • Javascript
  • jQuery
  • JSON
  • JSONP
  • Laptop
  • Learning Resources
  • Lists
  • Map
  • Metrics
  • Microsoft
  • miscellaneous
  • Mobile
  • NAPA
  • Office365
  • Opera
  • PDF
  • Performance
  • Personal
  • PHP
  • PM
  • PowerShell
  • Privacy
  • Programming
  • Rant
  • Safari
  • Science
  • Search Engines
  • SearchEngines
  • Security
  • SEO
  • Sharepoint
  • SharePoint2013
  • Silverlight
  • Software Engineering
  • Solutions
  • SQL Azure
  • SQL Server
  • TFS
  • Tip
  • Tips
  • Tools
  • Tools/Utilities
  • Trivia
  • TWIL
  • Twitter
  • UX
  • VM
  • VS.NET
  • VS2010
  • VS2012
  • WCF
  • WebApps
  • Websites
  • WF
  • Windows Phone
  • Windows7
  • Windows8
  • Word
  • WP7
  • WPF

Blog Archive

  • ►  2013 (112)
    • ►  October (16)
    • ►  September (14)
    • ►  August (8)
    • ►  July (8)
    • ►  June (13)
    • ►  May (12)
    • ►  April (12)
    • ►  March (8)
    • ►  February (15)
    • ►  January (6)
  • ▼  2012 (127)
    • ►  December (11)
    • ►  November (14)
    • ►  October (13)
    • ►  September (14)
    • ►  August (16)
    • ►  July (16)
    • ►  June (6)
    • ►  May (5)
    • ▼  April (11)
      • Archive tweets & favorites with Google Reader
      • Cloud Computing - Questions & Answers
      • Browser Developer Tools - Tips, Tricks, Documentation
      • Iframe facts
      • Hotmail's sign-up page uses...Google's ReCAPTCHA s...
      • Google Mobilizer Bookmarklet - view just text of w...
      • Get the ATVM card if you are a frequent traveller ...
      • JavaScript Performance tips
      • Getting started with SQL Server Reporting Services...
      • Low bandwidth? Try mobile version of popular websi...
      • There is an app for that?
    • ►  March (12)
    • ►  February (7)
    • ►  January (2)
  • ►  2011 (98)
    • ►  December (5)
    • ►  November (2)
    • ►  October (5)
    • ►  September (7)
    • ►  August (7)
    • ►  July (15)
    • ►  June (10)
    • ►  May (7)
    • ►  April (8)
    • ►  March (10)
    • ►  February (11)
    • ►  January (11)
  • ►  2010 (163)
    • ►  December (14)
    • ►  November (19)
    • ►  October (19)
    • ►  September (15)
    • ►  August (18)
    • ►  July (17)
    • ►  June (20)
    • ►  May (17)
    • ►  April (19)
    • ►  March (5)
Powered by Blogger.

About Me

Unknown
View my complete profile