The WHATWG Blog

Please leave your sense of logic at the door, thanks!

This Week in HTML 5 – Episode 3

by Mark Pilgrim, Google in Weekly Review

Welcome back to "This Week in HTML 5," where I'll try to summarize the major activity in the ongoing standards process in the WHATWG and W3C HTML Working Group.

The biggest news this week is the birth of the event loop.

To coordinate events, user interaction, scripts, rendering, networking, and so forth, user agents must use event loops as described in this section.

... An event loop has one or more task queues. A task queue is an ordered list of tasks, which can be:

Events

Asynchronously dispatching an Event object at a particular EventTarget object is a task.

Parsing

The HTML parser tokenising a single byte, and then processing any resulting tokens, is a task.

Callbacks

Calling a callback asynchronously is a task.

Using a resource

When an algorithm fetches a resource, if the fetching occurs asynchronously then the processing of the resource once some or all of the resource is available is a task.

Reacting to DOM manipulation

Some elements have tasks that trigger in response to DOM manipulation, e.g. when that element is inserted into the document.

The purpose of defining an event loop is to unify the definition of things that happen asychronously. (I want to avoid saying "events" since that term is already overloaded.) For example, if an image defines an onload callback function, exactly when does it get called? Questions like this are now answered in terms of adding tasks to a queue and processing them in an event loop.

The other major news this week is the addition of the hashchange event, which occurs when the user clicks an in-page link that goes somewhere else on the same page, or when a script programmatically sets the location.hash property. This is primarily useful for AJAX applications that wish to maintain a history of user actions while remaining on the same page. As a concrete example, executing a search of your messages in GMail takes you to a list of search results, but does not change the base URL, just the hash; clicking the Back button takes you back to the previous view within GMail (such as your inbox), again without changing the base URL (just the hash). GMail employs some nasty hacks to make this work in all browsers; the hashchange event is designed to make those hacks slightly less nasty. Microsoft Internet Explorer 8 pioneered the hashchange event, and its definition in HTML 5 is designed to match Internet Explorer's behavior.

Other interesting changes this week:

Tune in next week for another exciting episode of "This Week in HTML 5."

4 Responses to “This Week in HTML 5 – Episode 3”

  1. Ian Hickson says:

    Actually hashchange was in HTML5 before this week, and IE’s implementation is based on the HTML5 spec — the change this week was to correct the name of the event. It was called “hashchanged” in the spec, not “hashchange”. (I also added the onhashchange=”” attribute formally while I was at it, which is probably why it looked like I was adding the event, but actually the key part was already defined before.)

  2. To help the research-based approach HTML5 is taking, I’ve published my progress for the Collections of Interesting Web Pages.

    This hasn’t affected the specification and is very rough at the moment. But there are about 800 web pages with brief notes about interesting ways they use markup, divided into about 50 categories.

    I’ve just started doing some analysis of what I’ve collected. For example, how authors mark up headings.

  3. [...] Mark Pilgrim continues to keep us up to date with news in HTML 5 land. This week he talks to us about the birth of the event loop, and the hashchange event. [...]

  4. Daniel Shaw says:

    Maybe it probably due to the name and my association of it with TWiT and company, but I’d love to be able to tune into this as a podcast. I think it would be compelling even it were only a reading of the post. Just a thought.

    Thanks for keeping us posted.

Leave a Reply