The Uncertain Web: Pointer Event Polyfill and Chrome Fragmentation

Fat Stacks

The Uncertain Web might be out, but that doesn’t mean that I’m done talking about the current state of the open web platform. I’m going to get back to writing a little bit here (as there are no more books on the immediate horizon) and as part of that I’m going to cover some topics that relate to the book under this “the Uncertain Web” headline. Two such topics have bubbled to the surface in recent weeks.

Chrome Fragmentation

Peter Paul-Koch wrote about the ongoing fragmentation of Chrome (specifically Chromium based browsers) last week. He’s identified 11 separate versions on mobile and he details his findings in his post “Chrome continues to fall apart at brisk pace.

There are a lot of things about this that tie into what I’m talking about in the book.

For starters, you might assume that if you test in Chrome on a single Android device or, even worse, test in Chrome on the desktop with just the emulation feature of the Developer Tools you’re fine since it’s all “just Chrome.” That’s clearly not the case. This is exactly what I’m talking about when I urge you to “question your assumptions.”

Secondly, the importance of testing with real devices can’t be understated. I outlined a luxury testing strategy in the book that targeted a half dozen separate Android versions. As PPK’s article illustrates even that is not enough to get the full picture. Still, even falling short of a perfect testing plan, getting a variety of different devices running different Android flavors is important to ensure that you’re really testing your site or application and aren’t merely kicking the tires. Multiply that across iOs, Windows, and whatever else strikes your fancy and you’ll have a robust testing regime for the current state of the web.

Finally, this Chromium soup illustrates the importance of sticking to the tried and true methods of web development that we’ve established over the past decade and a half. Building baseline experiences that work across the broadest range of browsers and devices is going to be the best way to reach the widest possible audience. You shouldn’t have to worry about what browser people are using. 11 versions of Chrome shouldn’t keep you up at night. As long as you’re paying attention to features, using feature detection and device characteristics using media queries you’re going to be better off than if you’re sitting around fixating on the different versions and trying to piece together the differences into some bizarre matrix of pain.

I know there are a lot of people out there that have started to put together sites that only work in Chrome (including knuckleheads from Google that really ought to know better and should be setting a better example for the rest of the web.) That’s a terrible idea to begin with as there are hundreds of millions of people on other browsers out there. Then you factor in this inability to define what “Chrome” even is, and it’s clear that this new-fangled “this site is best viewed in Chrome” trend is even worse than the old-school “this site is best viewed in Internet Explorer” trend. At least back then it was a monoculture with just a handful of variations of IE in the wild and the browser’s penetration was nearly 90%.

Put some PEP in your Step

Since it’s an important aspect of modern web development that remains confusing for many developers, I wrote a whole chapter in the book on dealing with user input on the web. The importance of properly handling user input on the web should be obvious. If you can’t handle clicks of the mouse and taps of the finger on a screen, you’re not going to get very far as a web developer. It’s a complicated mess and plenty of smart people screw it up.

Check out Patrick H. Lauke’s Getting touchy presentation for the best possible overview (that doesn’t involve me re-writing a whole book chapter here.)

The tone of the chapter in The Uncertain Web was initially a hopeful one. There’a technology out there, Pointer Events, created by Microsoft and adopted by the W3C that unifies user input (mouse, finger, stylus, whatever) into a single API. When I initially wrote the chapter, there was support in Internet Explorer (obviously,) intent to implement from Firefox and an open issue to do the same (behind a flag) in Chromium. If all three had fallen into line then there would have been some possibility of forcing Safari’s hand and getting them, too, to implement this simplified interface. That was my hope at least and my tone (originally) reflected that.

Them, during the technical review for the book, the Chromium issue was closed. The Chrome team had decided against implementing Pointer Events in favor of unspecified “enhancements” to the existing Touch APIs So, I had to rewrite the chapter and cast Chrome as the villain in this particular tale. It was a bummer. Especially as, at the same time, the Polymer team deprecated support for their Pointer Events Polyfill. Suddenly we were down one browser and had no supported, high quality polyfill for the technology.

That’s the way the book went out the door. User input on the web was still a mess and Google was the villain.

Then, as the book was finally making its way onto the shelves it was announced that the jQuery foundation was taking over maintenance of the Pointer Events Polyfill. At least in my house, there was much rejoicing.

It’s still early days in the transition, but the project is already active on Github. I’m watching the project. You should too.

Pointer Events are, whatever Google thinks, a better solution to handling user input on the web. Beyond it being easier to code, and it is, it also does away with the conceptual problem many people have with this corner of web development. Despite serious effort from a lot of people, developers still think of it as a binary “touch” or “mouse” choice. It’s not.

If people start to think about “pointers” as a unified interface maybe people will stop doing things like the following example I’ve pulled from Wired.

If you visit Wired.com with a touch enabled laptop, mouse clicks simply don’t work. To activate many interactive elements you have to touch the screen. It’s super annoying.

Here’s why it happens.

Looking at their code, they’re using a ternary operator to create an event alias named touchity, by using crude test to set the event name as touchstart on browsers with touch capability and click on everything else:

var touchity = ( ('ontouchstart' in window) ||  (window.DocumentTouch  && document instanceof DocumentTouch) ) ? 'touchstart' : 'click'; 

So, later on, when events are bound and touchity is passed into jQuery’s $.on, under the hood, only touchstart or click is set:

$('.wp35-gallery .nav').add('.curtain').on(touchity, function(e) 
{
  autoPlay('forceStop');
  if (isThisADoubleTap()) {
    e.preventDefault();
  }
  if ($(this).hasClass('next') 
      || (event.target.id === 'curtain-right')) {
    offsetSlide(1);
  } else {
    offsetSlide(-1);
  }
}); 

This breaks on any device with a mouse and a touch screen. For a personal example, with my current set-up I’ve got a touch enabled laptop set up as a workstation 90% of the time. The laptop itself has a touch screen. The external monitor does not. When I visit wired, I get the “touchstart” events even though the screen I’m using isn’t touch enabled. This means the browser being touch-enabled is true on one screen, but not the other, no matter what the browser API reports to their crude test.

To activate a slideshow or other link on wired.com I need to drag the window from the external monitor to my laptop, reach up and touch the screen.

Sigh.

Pointer Events helps to make fundamental conceptual errors like that go away because you never think about whether it’s touch or mouse or stylus or three dimensional gesture or eye tracking or thought control or whatever. You just have a pointer.

So, follow the project, use the polyfill and then we can all bug Google to get back on the side of the angels.

A Long Journey Reaches a Happy Conclusion: The Uncertain Web is Out In All Formats

lrg

It’s true. After a two year odyssey, The Uncertain Web is finally out in every format that matters. The book has actually been out for a little over a month in multiple ebook formats from O’Reilly and Amazon; but owing to a slight production hiccup it hasn’t regularly been available in print until now (technically this Friday, but Amazon is on the case.) The book is in full color (and looks great) so I wanted to wait until you had the option to get your hands on the print edition before I really started to spread the news.

That time has come. I’m spreading some news…

I’m really happy with the finished product. One of the reasons I’m proud of it is that it’s the first book I’ve written that I could really recommend to my peers– my jQuery book was a hybrid effort with another writer aimed at intermediate developers and Beginning HTML and CSS is book for beginners. The Uncertain Web, on the other hand, works for everyone from a project manager or designer (who could read the first two and final chapters with ease) all the way up to the most technical front end engineer who might be surprised by some of the things that I kick around in my precious 224 pages. Not everyone is going to agree with everything I say in those pages, but there’s definitely something that will make you stop and think about the way you approach the web, no matter who you are.

Here’s how O’Reilly describes the book:

What’s the best way to develop for a Web gone wild? That’s easy. Simply scrap the rules you’ve relied on all these years and embrace uncertainty as a core tenet of design. In this practical book, veteran developer Rob Larsen outlines the principles of what he calls The Uncertain Web, and shows you techniques necessary to successfully make the transition.

By combining web standards, progressive enhancement, an iterative approach to design and development, and a desire to question the status quo, your team can create sites and applications that will perform well in a wide range of present and future devices. This guide points the way.

Topics include:

  • Navigating thousands of browser/device/OS combinations
  • Focusing on optimal, not absolute solutions
  • Feature detection, Modernizr, and polyfills
  • RWD, mobile first, and progressive enhancement
  • UIs that work with multiple user input modes
  • Image optimization, SVG, and server-side options
  • The horribly complex world of web video
  • The Web we want to see in the future

The book is also solely my idea. Which isn’t the case with any of my other books. Typically publishers have a book they want written andthey search for an author. This time I had some ideas I wanted to share and O’Reilly stepped up to let me share them (thanks to Simon St. Laurent.) That, in particular has been rewarding for me.


Have I mentioned I have a back cover blurb? I do. It’s provided by Jeremy Keith and it makes me smile.

“A refreshingly honest look at the chaotic, wonderful world of web development, with handy, practical advice for making future-friendly, backward-compatible websites.”


I also like this tweeted comparison:

All in all I’m a happy dude.

Check Out My Upcoming Webcast, Navigating the Uncertain Web

Hey! I’m doing a webcast on November 11, 2014 at 10 AM Pacific.* It’s called Navigating the Uncertain Web and you should check it out since it will be ridiculously great and it’s free.

Here’s what I had to say about it.

The modern web is a wild place. The proliferation of new browsers, new devices, new input models and new additions to the web platform have combined to create an environment full of uncertainty. It’s never been more difficult to create widely compatible sites. This webcast will show you how to approach compatibility in a nimble way and will help you to solve problems confidently when you’re faced with the web’s uncertainty.

If you’re interested in my book, The Uncertain Web, then this webcast will be right up your alley.

Speaking of the book, I’m finally going to be done with the first draft this week and will be working on getting it ready for production throughout September. It’s been an epic journey getting to this point so I’m ecstatic to see the finish line approaching.


* 6pm – London | 1pm – New York | Wed, Oct 8th at 4am – Sydney | Wed, Oct 8th at 2am – Tokyo | Wed, Oct 8th at 1am – Beijing | 10:30pm – Mumbai

My New Book, The Uncertain Web, is Available in Early Release

rc_lrg

The raw stuff, available for your reading pleasure. I’m really excited to see what people think.

The best way to approach the web today is to forgo hard and fast rules and design for uncertainty. Embracing uncertainty as a core tenet of web development and scrapping the rules we’ve relied on in the past few years is the best bet for creating future proof web solutions. By combining web standards, progressive enhancement, a full technical toolbox, an iterative hybrid approach to design and development and embracing a desire to question the status quo and perceived wisdom, teams can create dynamic web sites and applications that should perform admirably in future devices, with unknown capabilities. By focusing on optimal solutions with intelligent fallbacks and forgoing the desire for absolute solutions design and development can work together to create the web of today and tomorrow.

Introducing My New Book: The Uncertain Web

Hey everybody, I’ve got a new book coming out. It’s called The Uncertain Web and it’s being published by O’Reilly. Right now we’re targeting a November release.

Just in time for Christmas. Buy a dozen and hand them out like candy canes.

If that seems like too long to wait, never fear. I’m about 50% finished and once that chunk has been hammered on by a hand-picked team of geniuses, it will be available as an Early Release.

So, what’s it all about?

Here’s my original pitch:


The Uncertain Web

The best way to approach the web today is to forgo hard and fast rules and design for uncertainty. Embracing uncertainty as a core tenet of web development and scrapping the rules we’ve relied on in the past few years is the best bet for creating future proof web solutions.

In the early 2000s, there was basically one browser (Internet Explorer 6,) one platform (Windows XP) and one screen resolution (1024 by 768) that mattered. With that set up you could design, develop and test against the vast majority of web users with one desktop computer. The biggest question on the horizon, it seemed, was when it would be viable to design for 1280 pixel screens

This limited field of play meant that there was an expectation that sites and applications would look the same everywhere for everyone. Best practices were honed and codified into hard and fast rules which drove design and development. Major choices, such as the size of the basic grid to design for, were no longer choices. You started with a static, 960 pixel grid and sliced and diced it as needed.

Today, things couldn’t be more different. With the launch of the iPhone and the iPad, the rise of Android and the growth of not just one, but two real contenders to Microsoft’s position as the dominant web browser (Firefox and Chrome), developers and designers have an ocean of variables to navigate. Every question around a site design is now pregnant with options.

Initially, developers and designers tried to navigate this new reality by creating new rules.

The problem was, the goalposts kept moving. As soon as a new hard and fast rule was created, some new wrinkle would render it impotent.
People designed and built “iPhone” sites, assuming that Apple’s dominance in the smartphone market was somehow a permanent condition. They tested for touch capabilities and assumed that touch users would never have a mouse.

As Android’s huge growth over the past few years, and the presence of devices like the Chromebooks and Windows 8 laptops with both mouse and touch capabilities have proved that those new rules have a short shelf life.

Even patterns like Responsive Web Design, which some saw as a single solution for design and development moving forward fall apart when applied against complicated application patterns and the vagaries of bandwidth and mobile performance.

By combining web standards, progressive enhancement, an iterative approach to design and development and embracing a desire to question the status quo and perceived wisdom; teams can create dynamic web sites and applications that should perform admirably in future devices, with unknown capabilities. By focusing on optimal solutions with intelligent fallbacks and forgoing the desire for absolute solutions design and development can work together to create the web of today and tomorrow.

This book will outline both the concept and underlying principles of the Uncertain Web and introduce some of the techniques necessary to make the successful transition.


So, that’s the thing.

I’m really excited about this one. I hope you enjoy it.