SOS

Shane O'Sullivan's technical blog… really ties the room together

Archive for September, 2011

JavaScript performance tips

Posted by Shane O'Sullivan on September 28, 2011

Every now and again a question comes up at work as to which of two or more approaches to the same problem in JavaScript performs better. I’ve started using the fantastic site jsperf.com to document these, so I’ll append to this post whenever I add a new test. I hope you find these useful, as they are answering questions that pertain to practical JavaScript usage.

Creating a regex inside and outside a loop

Declaring variables in a loop or outside it

Using hasOwnProperty or testing with undefined and void 0

Using indexOf or substring to test the end of a string

Extend Without Foreach

Posted in Javascript, performance | 1 Comment »

Tip: Declare regular expressions once and reuse for performance win

Posted by Shane O'Sullivan on September 22, 2011

A pattern I see quite often in JavaScript is of people using a regular expression in a loop, e.g.

 

for (var i = 0; i < array.length; i++) {
array[i].match(/something/);
}

The naive assumption is that a regex is some special native thing, like a boolean. However regular expressions have a cost to construct, which you can see in this performance test – http://jsperf.com/creating-a-regex-in-and-outside-a-loop

So, if you’re using a regular expression in JavaScript more than once, declare it first and reuse it to see a dramatic performance gain

Posted in Javascript | 3 Comments »

CSS Box Sizing makes me happy

Posted by Shane O'Sullivan on September 13, 2011

Quick note: For anyone fighting for years against the CSS box model, where the visible size of an element depends on the sum of it’s width, height AND padding, check out the box-sizing: border-box;. It does exactly what we need, where if you say


.myclass {
width: 100%;
padding: 10px;
}

then myclass will still take up 100% width of its container, instead of overflowing.

https://developer.mozilla.org/en/CSS/box-sizing

Posted in Technical | Leave a Comment »

This is what a successful platform launch looks like

Posted by Shane O'Sullivan on September 2, 2011

… pity it had to happen as a result of a liquidation sale.

WebOS looks to be on it’s last legs, and HP has announced that it’ll never make new WebOS hardware. In the meantime, the fire sale of TouchPads has done fantastic things for us WebOS developers. The image below is a graph of the Flickr Mundo HD sales for 2011.

If only HP had anything resembling courage, rather than wimping out with the revelation that “Competition is hard? What? No one told me! Run away!!”, this sales trend might have actually continued for a long time.

Ah well, I’ll enjoy it while it lasts!

Touchpad Sales of Flickr Mundo HD

Posted in apps, Flickr Mundo, Palm, Tablet, WebOS | 2 Comments »

 
Follow

Get every new post delivered to your Inbox.

Join 533 other followers

%d bloggers like this: