Archive for the ‘thoughts’ Category

Use Array.join instead of concatenating strings?!?

Thursday, September 6th, 2007

I read this article at Usable Type and said to myself – true, true, true, true, WTF?

So I did a quick test:

  1. Concatenating 3 long strings: without ~135ms (45ms) [25ms] {33ms}, with ~220ms (120ms) [40ms] {65ms}
  2. Concatenating 12 shorter strings: without ~215ms (190ms) [85ms] {90ms}, with ~470ms (180ms) [105ms] {165ms}

The tests were done on my laptop on Windows Vista in Firefox (IE7) [Safari3] {Opera 9.2}, the function was repeated 10000 times. It seems that you’re better off without using array.join(), though it might be an option for huge joins in IE.

I wonder what sparked the idea – I’ve seen the use of arrays for string operations in Flash – string.split(old).join(new) for replacing until a proper method was available. I’ve never thought about abusing JavaScript that way…

On a side note – have you noticed that Firefox was significantly slower than others?

Update: I created a test page so you can test your browsers and post a comment

Firefox and Opera statistics are underrated

Wednesday, September 5th, 2007

While testing browser behavior regarding inline JavaScript evaluation and the back and forward buttons I found a very interesting thing. When a script is included in the HTML to execute on parsing (not on load but inline) Internet Explorer (7 on Vista tested) and Safari 3 for Windows will re-execute the script when a user returns via the back button. In my mind this is the correct behavior, since you actually visited the page twice.

The thing is that Firefox (2.0.0.6 on Vista tested) and Opera (9.20 on Vista tested) don’t agree with me. Well maybe they do and don’t live by their beliefs. What they do is nothing. You come back and no scripts are executed. Not even one request is sent to the server in Firefox.

This “feature” is sometimes a great thing – all the AJAXy stuff and all the JavaScript enhancements are already there and don’t need to be rendered again in turn saving power and time. At other times it’s a pain in the a** since some stuff does return to its default state and some doesn’t. This problem is most often observed with dynamic/advance forms that lose their default values/states. Since even onload is not fired this can get annoying…

Besides all the interface problems you might encounter due to this “rogue” behavior, there are also a few issues regarding statistics. It’s harder to inspect the path of a user, the time a user spent on a page, the number of page views in a visit and other related metrics. The other significant issue is that browser usage statistics might be skewed. To answer this last issue we’d have to know how these statistics are measured.

Let’s take a user that is used to clicking the back button while navigating a site with a 2 level deep navigational tree. She comes to the page, goes in one branch and then to a second, very distant branch. Internet Explorer would register 7 page views (1 on the root, 2 to get down, 2 back up and 2 more down), while Firefox would only register 5 page views (1 on the root, 2 to get down, ignore the 2 back buttons, 2 more down) – a 1.4:1 ratio.

If the statistics are based on sessions or unique users we have 50% IE and 50% FF. If we base them on hits we have 58% IE and 42% FF – a 16 percentage point difference or as we said before a 40% difference. This is not something you could just ignore…

Exercise for the reader – why do “unsupported” browsers always have a small browser share in hit based browser metrics?

No mouse for you mister!

Monday, September 3rd, 2007

It finally arrived, but they left. Before closing time. Not going back there.

Noscript with script?

Saturday, September 1st, 2007

When I was debugging a script last week I found a hilarious statement in it:

document.write('<noscript><a href="..."><img src="..." «
alt="..." /></a></noscript>');

My new mouse – not yet

Friday, August 31st, 2007

When I first read about the new mice Logitech was releasing this month I immediately decided to by the new laptop mouse – the VX Nano. It’s going to look perfect plugged into my X60t‘s slightly indented right side USB slot.

I’m currently using a NX20, a corded optical mouse I bought a while back. The main reason was that all my USB plugs on my previous laptop were at the back, which meant I could easily forget that I have a wireless receiver plugged in and break it. Hey it happened before, fortunately the USB key (sort of) survived. You can also wind the cable around the NX20 so it doesn’t get mangled while traveling. It’s a great little laptop mouse and it’s serving me well.

So when I got back home (I read about it in a local gaming magazine Joker at my parents’ home) I immediately checked online to see when the Nano will be available. I said end of August – good enough. Next step was obvious – trying to find it on the page of the local reseller. Nothing. Weird. No launch date, no expected price, no nothing. Not a big surprise though so I went to visit them. It was probably around the 20th – so strictly speaking it was almost the end of August. They said that it’s coming and that the latest news they have is that it’s going to be in the stores on the 24th. As I later found out it was probably a misunderstanding – it probably meant that it’ll be released on the 24th which actually means leaving a warehouse somewhere in Europe.

Since I work near the place I visited the store a few more times. On Thursday, the 23th, they figured that it’s not going to be there on Friday but maybe Monday, but probably Tuesday, the 28th. When I came by on Tuesday they told me it’s not there yet and that I can leave my phone number so they’ll call me when it arrives. I decided I’ll rather call them myself. Did that on Wednesday – not there yet. Since I couldn’t get through yesterday, the 30th (was that I private call I was listening to for 5 minutes while standing in the store?) I stopped by – not there yet.

All this wasn’t really a surprise. The real surprise was that they have no idea when it will actually be available. Citing their words: “We don’t know which driver is bringing it so we cannot check where the shipment currently is and when it will arrive.” Now I’d immediately think that’s BS if I didn’t know the (low) level of service in my beloved country. And this was even more shocking than having a sales person lying to my face. How is it possible that a logistics company exists that cannot tell you where your shipment is and when it’ll arrive when it’s supposedly already a few days late?

I’m still waiting for the mouse, getting grumpier by the day. Why didn’t they just say it’s coming in the beginning of September?

Calendar APIs

Monday, August 27th, 2007

I’m looking for a calendar web-app with full API access. I really don’t want to reinvent the wheel…