My Work Blog

Long polling Comet

Friday, February 5th, 2010

I’ve been working on a long-polling comet client from Amix at Plurk, who uses it to monitor messages on the server. While he simply provides it as a ’solution’, not detailing the hurdles he overcame to get there, it’s clear that there’s some thought gone into it.
http://amix.dk/blog/post/19489#Comet-long-polling-for-all-browsers-using-ScriptCommunicator

The script requires you to set a variable in your jsonp response. The script checks whether that variable is true after the jsonp loads. If true, your json has loaded. If not, something has gone wrong.

So, if your jsonp looks like this:
callback({blah:”blah”});
You’ll need to revise it to this:
callback({blah:”blah”});ScriptCommunicator.callback_called = true;

On the jQuery forums, John Resig said he isn’t enamoured with this approach since it means adapting the jsonp response, and if you’re using jsonp then you’re probably not in control of the feed. It’s a fair point, but you could simply add the callback_called variable into the callback function instead.

Plus, if you’re running Comet long-polling, it’s better to use a different domain for your comet feed, to prevent tying up threads in the browser. So jsonp is needed.

The “difficult” part of the process is knowing when to run the second script, that checks the callback_called value. Amix uses a variety of methods for different browsers to achieve this.

In Firefox (default case) -> create two script tags using document.createElement, and attach them to the body.

In IE -> use the onreadystatechange event to call onSuccess, and then detect errors there, based on the readyState (somewhat illogical).

In Safari/Chrome -> write two script tags out with document.writeln. Presumably, this is intended for use with an iframe, though that’s not clear. OOTB, no webkit browsers receive data.

Having tried to hack the script to make the Safari browsers use the same method as Firefox, I’ve found that Safari’s caching kicked in and failed to load new scripts from the server (though this could be my fault for not changing the script name each time).

Looking back at Plurk, the comet scripts are indeed in an iframe, so I think this script probably needs some more input before it’s going to work for anyone else. Hopefully, Amix (or someone) will put together a demo page and make any necessary fixes to the script when making that work.

It’s a very useful function/tool/script. Thanks Amix.

Typekit

Tuesday, January 19th, 2010

It’s not often I write a blog post just about a new tech.  For good reason:  there’s always someone out there prepared to dedicate a bit of time to a full tutorial on implementation, pros and cons.

I’d just like to mention Typekit because it’s not what I thought it was, and I’m quite impressed with what it is.

I’d assumed Typekit was a solution to the technological problem of including new fonts on webpages.  Along similar lines to Cufon and sIFR.

For those who don’t know, including fonts is a problem because modern browsers haven’t agreed on a way to distribute fonts with web pages.  IE, oddly, had this solved ages ago, but since MS is so unfashionable at present, it has been largely ignored.

Cufon lets you use a new font by replacing text with little <canvas> image elements.  Ingenious, but quite silly as you have to create loads of these little elements on the fly.  SIFR does the same thing, but using Flash.  Indeed, we once used sIFR for the Cannes Film Festival website.  I remember a very long page-render time…

I’d assumed Typekit was going to be similar. Basically, I’m wrong.

Typekit is a solution for font licensing. It’s always been a pain to get the right licenses for fonts. Often the licenses you buy are both extortionately priced and not licensed to web distribution. (This is because the way you provide a font to a web page is easily hijacked, and the font can be stolen).

Typekit provides access to their sensibly-sized library of fonts on a variety of subscription schemes. Once signed up, including the fonts is a simple matter of a few lines of JavaScript.

Technically, Typekit uses the @font-face download rules. This means it supports a limited number of browsers. But it also supports IE, using the EOT font format (IE’s system attempts to prevent hijacking of fonts too). So it’s not bad.

Downsides are that the iPhone is not supported, as mobile Safari doesn’t seem to support @font-face. Of course, the non-JavaScript browsers out there don’t see the new fonts (but they’ve asked for a lesser experience, so who cares). Also, there can be a FOUC (Flash of Unstyled Content) as the page loads the first time.

Once request I’d make to the Typekit team is the ability to support two sites on the Tester pack. One for my simple blog, one for active development. I know you want me to pay, but my commitment to fonts for personal use is not so great, and since you add your logo, it’s only an advert for yourselves anyway isn’t it.

In summary, I think it’s a great idea. I see Typekit as the Spotify of fonts.

Leaving Digitas

Sunday, December 20th, 2009

I’ve been at Digitas for five years. Five years. As I’ve recently learned, that’s about thirty-five dog years. Which is about four years older than I am now.

Here, I’ve worked on websites for Hewlett Packard, the Cannes Film Festival, Persil, Nicquitin, General Motors, Opel, Vauxhall, Sega’s TotalWar, Nakheel and the Palm Jumeirah, Bayer’s Xarelto, MSD’s Propecia, Procter & Gamble, Eukanuba, Digitas of course, and a few sites so cool, I still can’t tell you about them.
That’s not a bad record.
Estimates suggest that on average*, I have been involved with more than seventeen percent of your household purchases , and although I have a three-percent chance of killing you with a car, there’s an extra four percent chance of saving your life after an operation.

Somehow I’ve been sent to Brussels, Warsaw, Geneva, Minsk, Basle, Kiev, Zurich, Paris and Bangalore.

Ninety-two of my facebook friends, I met through Digitas. That’s sixty-one percent.

Since I joined Digitas, I’ve started and finished a three-year degree in Physical Science, with a two:one. I’ve got married, and twenty-five percent of my guests were from Digitas. I’ve run twenty-six point one miles in the London marathon, and they helped me raise three-hundred pounds for the NSPCC.

I loved working here.
I wish them all a great 2010.

Kenneth

* some estimates may be approximate to the point of complete fiction.

Nice Cost-Benefit Graph

Friday, June 6th, 2008

Jeff Veen at @media showed a nice graph, and Indi Young used it afterwards.  But I don’t have a copy of it, so I’ve recreated it below.  I think it shows really nicely the benefit of discussions early on, and the impact of a change of mind later on.

It’s great:  At the start, you can have whatever you like.  Near the end, even if you change the tiniest little thing, it has an impact.

The aim of the graph is to encourage talking and interaction at the beginning, not scare people about cost.

Talking vs Impact Graph showing benefit of talking early on versus the high cost of changing your mind later on.

Xobni

Tuesday, January 29th, 2008

I’ve been playing with Xobni (Inbox backwards) for a week or so.
http://www.xobni.com/

It’s a fantastic plugin for Outlook.  So slick.  The best search for email I’ve seen, and an automated contacts list (who keeps theirs up to date manually?  honestly?).  What more do you need?

They’ve proved Microsoft are years behind the curve (ok, I haven’t tried 2007 – but they haven’t shown me why I should pay, again).  And they’ve proved (like many Web2.0 companies), that Indie bands haven’t used up all the cool band names yet.

Let me know if you need an invite.  I’ve got 1 left.