Sunday, April 1st, 2007

The New Timers

Ask any self-respecting Ajax developer how they time events, and they’ll tell you “I use setTimout()” or more likely, “I use setTimeout(), duh”. However, two new Ajax patterns are making that “duh” seem just a little tenuous. One new timing technique relies on the notorious <blink> tag, the other is all about the whitespace. That’s right folks, setTimeout() is about to go the way of the fob watch.

  • <blink> timing For a long time, the ignoble <blink> tag seemed destined for all the one-hit wonderness of a Vanilla Ice or an MC Hammership. Loved for a month or two, then cast aside with nought but the occasional fond memory. Yet in an unanticipated turn of events, intrepid developers have recently been asking hard questions about <blink>. “If it was really as dumb as people make out, why was its timing so precise?” asked one Ajax guru who wished to remain anonymous on the grounds that he had been consuming Red Bull for the past eight hours. Another guru in questionable state pointed out “setTimeout() isn’t all that! Did you ever try it in lynx? Total no-op!” And so it was that <blink>’s true purpose became known. Reborn as much out of frustration with setTimeout as it was with the promise of a more robust solution. No longer eye candy, but a super-precise timing mechanism. The thinking geek of 2007 embeds a single <blink> tag on the page, hides it with CSS, and arranges all application scheduling against the swift oscillations of this postmodern crystal timer.
  • HTML whitespace. If you’re still working in Ajax 1.0, you probably haven’t paid much attention to the biggest portion of your HTML – the whitespace. But then, three-quarters of the world is water, and where do we devote all our attention? So it’s hardly surprising that whitespace’s virtue has largely gone unnoticed. In design, getting whitespace right is a vital task, and likewise in modern Javascript code, whitespace is everything. The secret of HTML whitespace is that programmers can use subtle variations to affect speed of processing. Say you have a script that needs to interact with an element of your page. You need the element on the page first, before the script can run. The old, clunky, way would be to rely on document.onload. The new way is to output the element first, followed by 1-2MB of whitespace, followed by the script tag. By the time the whitespace has been processed, the element will have been placed on the page. You may object to all this whitespace consumed by this hack, but bandwidth is cheap these days and IDEs can hide it while you’re developing. So what’s the catch now, wise guy? With the trend towards parallel computation, whitespace promises a way out of the concurrency and synchronization headaches that Ajax developers often endure.

We’ve yet to see these facilities live, but then we haven’t yet seen Vanilla Ice live either and he’s doing just fine. setTimeout() is dead, long live the <blink> tag!

Posted by Michael Mahemoff at 6:49 am
21 Comments

+++--
3.8 rating from 66 votes

21 Comments »

Comments feed TrackBack URI

Yeah! April fools to you too!!!

Comment by SchizoDuckie — April 1, 2007

Yep I use a much simpler version of it, the
userBored() function.
It looks like that:

while ( userBored() == false ) {
// continue displaying same content
}

When the user is bored by the never-changing content, he can click on one of those underlined thingys that display other content.

Works like charm, with and without JS, crossbrowser compatible and it is fully compliant with the blink tag solution.

Comment by Frank Thuerigen — April 1, 2007

I don’t use setTimeout, i use fn.delay ;) This april google is number april fools winner :D

Comment by digitarald — April 1, 2007

I know we’re not serious here, but don’t you mean setInterval? Wouldn’t the blink tag, which “runs” continuously be more analogous to the setInterval function, which runs continuously until cleared, rather than setTimeout, which runs once?

Comment by Cody Swann — April 1, 2007

What i really loved was that the post has an exact rating of 4.1 when I hit the site. Thought it was intentional, but it doesn´t seem so when I rechecked it with another browser

Comment by Philipp — April 1, 2007

I nearly cried when I read “followed by 1-2MB of whitespace.” LOL, great stuff.

Comment by Chris Huff — April 1, 2007

I’m waiting for the w3c to include the very undersupported tag for HTML 5, word on the street, is (thankfully) it’s right around the corner.
I finally feel like I can think about retiring my Behavior.Seizure library, and won’t have to deal with rewriting doSeizure() to support the latest version of JAWS.

Comment by naterkane — April 1, 2007

I am using combination of document.newThread() and document.sleep()

Comment by Dragan — April 1, 2007

That joke made me cry, it was that awful.
My april fool’s day has been ruined, I can no longer laugh.

Comment by Shawn K — April 1, 2007

my god, i thought you guys went nuts…

Comment by add — April 1, 2007

These “jokes” aren’t such bad ideas. I know that Mozilla has problems with setTimeout(). And the BLINK tag was invented by Mozilla. So maybe there is some kind of event that fires for the BLINK element that is more reliable that setTimeout? And using whitespace to force a rendering delay doesn’t seem stupid either. Not if you document.write() it. I always fall for April Fools jokes anyway. This year is probably no exception. I’m offer to look for BLINK related events…

Comment by Dean Edwards — April 1, 2007

hehee a good try :-)

Comment by Adnan Siddiqi — April 1, 2007

You forgot to mention that the ECMA just decided that JavaScript 2.0 will support Ook! datatypes and goto constructs.

Comment by kourge — April 1, 2007

Both blink frequency and timer implementation are OS API calls, so there is no specific difference and for both you can say they count within the OS capabilities of precision. Linux is more precise in that than WinXX, but no substantial gain here.
BTW Dean I sent you an eMail to d@e.n and that was no april joke… ;-) I hope you considered reading it :-)

Comment by Frank Thuerigen — April 1, 2007

@Frank – message received. It looks very interesting.

Comment by Dean Edwards — April 1, 2007

Glad you like it… ;-) any comment on the named issue is much appreciated…
Back on topic: I noticed your HP favicon blinks every once in a while. Is that due to the adamant precision of the timer you tried so hard to hide away from the community?

Comment by Frank Thuerigen — April 1, 2007

Mr. gullible here

Comment by Ivan — April 1, 2007

The blink one had me hook-line-and-sinker, but the whitespace gave it away. 1 – 2MB of whitespace – hilarious! :)

Comment by Andy Hume — April 2, 2007

Here I was thinking it was another article by a JS developer with WAY too much time on his hands, creating yet another shining example of what happens when someone with too much brain power decides to code some Javascript.

…Then I read the whitespace paragraph, and remembered to check the date of the article. Good one guys… :-)

Comment by Jeffrey Robbins — April 2, 2007

Ok, yesterday I would’ve kicked myself for not realizing that this was an april fool’s post; luckily today is today and I can chalk up my stupidity to the fact that it’s the 3rd of april now. Why are april fools stories still on the front page? :(

Comment by Photoflock — April 3, 2007

to prevent the borg from taking over.

Comment by Frank Thuerigen — April 6, 2007

Leave a comment

You must be logged in to post a comment.