At 7:30 am on Tuesday, I was back at the squeaky-clean-new UCSF Mission Bay campus, chompin’ at the bit for more of that good widget scoop. Along with Monday’s program, this would surely be more widget smarts than a person could get anywhere else on the planet — at least this week. Tuesday’s session was to have a different purpose: producer Niall Kennedy had planned it that way [and hats off to him for a great job putting this event together!]. Monday was about the business of widgets and large trends affecting the industry, while he told us Tuesday was for getting into the nitty-gritty, helping attendees plan their widget implementations. And there was no question in my mind that most of the 200+ attendees at Widget Summit 2007 were in fact developers — or, as Niall described them in the conference materials, the people "directly involved in this hyper-growth industry, providing the tools and content that connect people and their ideas across the web."
On this day, I would take deep dives for you, oh valued readers, in Javascript widget basics, advanced Javascript. Microsoft’s Popfly and Silverlight, Facebook development, iPhone widget development, and — last but certainly not least — Google Gadgets.
Dori Smith, a well known programmer and author of Javascript books (published by O’Reilly and others), led the first session. She told us how the term "widget" isn’t really well defined — it means different things to different people.
In the Apple world, for example, there’s the "widget object," while in the Vista world, there’s the "system.gadget" object — but they’re different things. She also called the industry on the "write once, run anywhere" claim — calling it a myth. "Unless it’s something really, really basic," she said, "you’re going to have to tweak the widget for different platforms."
So, what should your considerations be when creating your first widget? Dori set out a great list:
• what do you want to do?
• is it community-oriented and viral? or maybe just something simple, like a countdown to an event?
• is is static or dynamic?
• will it require frequent updates?
• is it for a web page or not?
• what platform will you use?
• what does your audience want?
Dori said cross-platform woes can be best dealt with by separating content from style and behavior: HTML for content, CSS for style. She recommended you start by making your widget work without Javascript, then add JS functionality without touching the HTML. She said DOM (Document Object Model) lets you manipulate with Javascript without affecting the HTML.
The biggest complaint about widgets is that they’re slow, Dori said. The solution? "Better written widgets!" Let the page finish loading, she said, adding that there’s a simple workaround to this problem. (Presumably, you have to read one of her books.)
What’s Dori’s crystal ball? First, she’s really looking forward to Leopard coming out on October 26. She’s seen a lot of the new stuff coming in this OS upgrade, but can’t talk about it. One thing she could mention: "Dashcode" — a development environment for widgets. "I love this product!" Audience question: "But is it only for Mac OS dashboard widgets?" Dori’s answer: "Yes, but you can create graphics you can use on other platforms." She also really likes the new "WebClips feature of the new Leopard OS. "It allows people with no interest in code to make their own widgets."
Programmers are increasingly understanding the impact of widgets, Dori said. "And users are more willing to install widgets." She warned, however: "Platform incompatibilities will get worse before they get better…The standardization process will help," she said, "but it will take a long time."
Since this was a session on Javascript, what about that other kind of widget? "Could you comment on Flash?" asked an audience member. "There are lots of people out there with iPhones," she said, "which don’t support Flash!" The questioner countered: "But Javascript doesn’t work on MySpace." Dori countered back: "Yes, but you can use DHTML. It really depends on what you want to do." Flash is much more visual, she allowed, but it’s also an expensive product to buy. And the final good insight from Dori: "Anything you can do in Flash you can do in Javascript — on one platform. The problem comes with multiple platforms."
But, as if this session wasn’t enough on JS, there was more coming. Joe Smarr, the young, animated chief architect at Plaxo, jumped right up on the stage to continue the fun. [Joe is the son of famed computer scientist Larry Smarr.] Plaxo, Joe reminded us, was doing Ajax iframes in 2004. It now has 20 million users. "Why is JS special?" Joe asked.
"Because you’re downloading real source code and running it in the browser," he said. And downloading and running JS blocks the browser, and the UI thread. "Code from different domains is executing together," Smarr said. "You can do a lot of good with Javascript, but you can do a lot of harm, too."
The biggest piece of advice from Joe: "Make your widget NOT slow the page down — or open any security holes. Make it fast." He also put in a plug for Firebug (a Firefox plug-in for coders): "It’s the web hacker’s best friend. Makes it really hard to keep developing in IE." Joe gave us his secrets for high-performace widgets:
• write less code
• draw HTML efficiently
• yield early and often
• profile like crazy
He had this opinion as well: "innerHTML is way faster than DOM manipulation." On the subject of best practices in Javascript, Joe stressed, "Give your functions unique names! You’re in a shared namespace. Otherwise, you can clash with others." For security, he said, "use JSON and callbacks for third-party API calls." For more info, Joe said to check out his blog — two specific posts to look for there have "OScon" in the title. He’s also pointed to a video of him presenting on this same topic at OScon. An audience question: "What about multiple widgets on the same page?" Joe’s answer: "You have to worry about those widgets fighting each other. Each one should have its own ID….And don’t assume too much about the host environment."
More to come later from me — one more post, wrapping up the rest of Tuesday’s program.
Recent Comments