Realcodeart.com

jQuery

A function named with a dollar sign, and a shortcut for when the page is ready.

John Resig, 2006

Get it on a mug or tee →

In January 2006 John Resig released jQuery. He had shown it at BarCamp in New York, to a room of people who were tired of writing a different DOM call for every browser. Internet Explorer and the browsers that were not Internet Explorer disagreed about how to find a node, how to attach an event, and how to know that the document had finished arriving. Libraries before jQuery, Prototype among them, had already tried to paper over the fight. Prototype had claimed the dollar sign. Resig claimed it too, and later shipped a way to give it back, because a global name was a territory.

The idea was small enough to say in a sentence. One function creates a wrapper around a selection, or around a node, or around a function you want run when the page is ready. Methods on the wrapper return the wrapper, so a call can be chained: find, change, bind, and do not lose the set. For a decade a large share of the web called that function. Tutorials started with a script tag and a dollar. Designers who did not think of themselves as programmers could hide an element or fetch a fragment of HTML. The library's slogan, write less, do more, was advertising. The chaining was the actual product.

The bars show the opening of the function, the fork at the door. If you pass a function, and the ready helper exists, the function is scheduled for the moment the document is ready. Otherwise the argument is treated as a selector, or as a node, or as another jQuery object. That fork is the famous shortcut. It is also a history of the bugs it prevented. Waiting for the load event meant waiting for every image. Waiting for DOMContentLoaded was not portable yet. The ready path was the library agreeing to worry about that so the caller would not.

Version 1.0 arrived later in 2006, once the experiment had users. The selector engine grew up. In 2009 Sizzle split the hard part, matching CSS selectors across broken browsers, into a component other libraries could borrow. jQuery UI and a plugin ecology piled on. Then the browsers caught up. querySelectorAll became real. addEventListener became the path you could teach without a footnote. Fetch replaced the ajax helper for new code. The library did not vanish. It remained in the pages already shipped, which is a larger country than the pages being written this week. Maintenance moved under the jQuery Foundation and then the OpenJS Foundation.

The MIT notice on the product page is the current one, including the foundation's copyright. MIT is a permission, and it is also a condition: the notice has to appear in copies. This page is where it appears. The bars are not a copy of the whole file. They are the opening fork, the ready check and the start of the selection logic, from the early source. A dollar sign is not in the picture, because the picture has no letters. The shape of the fork is the portrait. Two paths, one function, a web that called it until the platform learned the same tricks.

The excerpt stops where the idea is already visible, before the library becomes a catalog of effects. Animation, deferreds, and the ajax helper are later rooms in the same building. They are not the door. The door is the test at the top: did you hand me a function, or did you hand me something to find? A gift buyer can see two weights of line without knowing the browsers of 2006. A programmer can see the ready-path and the selection-path as the fork that replaced a page of compatibility notes.

Resig kept working in public, and the foundation kept the license. The copyright line names the OpenJS Foundation and other contributors, and it points at the foundation's site. This essay does not reprint the MIT permission in full because the product page already does, as the license requires. The history here is the door, the decade it stayed open, and the standards that eventually learned its job.

The name on the cup is the library. The name on the page is Resig, the year, and the foundation that holds the copyright now. Between those two names is the usual life of a popular file: more authors than the announcement listed, a license that stayed MIT, and a function signature that outlasted the browsers it was written to endure.

Mug and tee of jQuery