Polyfills and products

I was chatting about polyfills recently with Bruce and Remy—who coined the term:

A polyfill, or polyfiller, is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively. Flattening the API landscape if you will.

I mentioned that I think that one of the earliest examples of what we would today call a polyfill was the IE7 script by Dean Edwards.

Dean wrote this (amazing) piece of JavaScript back when Internet Explorer 6 was king of the hill and Microsoft had stopped development of their browser entirely. It was a pretty shitty time in browserland back then. While other browsers were steaming ahead with browser support, Dean’s script pulled IE6 up by its bootstraps and made it understand CSS2.1 features. Crucially, you didn’t have to write your CSS any differently for the IE7 script to work—the classic hallmark of a polyfill.

Scott has a great post over on the Filament Group blog asking To Picturefill, or not to Picturefill?. Therein, he raises the larger issue of when to use polyfills of any kind. After all, every polyfill you use is a little bit of a tax that the end user must pay with a download.

Polyfills typically come at a cost to users as well, since they require users to download and execute JavaScript in order to work. Sometimes, frequently even, that cost outweighs the benefits that the polyfill would bring. For that reason, the question of whether or not to use any polyfill should be taken seriously.

Scott takes a very thoughtful approach to using any polyfill, and I try to do the same. I feel that it’s important to have an exit strategy for every polyfill you decide to use. After all, the whole point of a polyfill is that it’s a stop-gap measure until a particular feature is more widely supported.

And that’s where I run into one of the issues of working at an agency. At Clearleft, our time working with a client usually lasts a few months. At the end of that time, we’ll have delivered whatever the client needs: sometimes that’s design work; sometimes its design and a front-end pattern library.

Every now and then we get to revisit a project—like with Code for America—but that’s the exception rather than the rule. We’ve had to get very, very good at handover precisely because we won’t be the ones maintaining the code that we deliver (though we always try to budget in time to revisit the developers who are working with the code to answer any questions they might have).

That makes it very tricky to include a polyfill in our deliverables. We’d need to figure out a way of also including a timeline for revisiting that polyfill and evaluating when it’s time to drop it. That’s not an impossible task, but it’s much, much easier if you’re a developer working on a product (as opposed to a developer working at an agency). If you’re going to be the same person working on the code in the future—as well as working on it right now—it gets a lot easier to plan for evaluating polyfill usage further down the line. Set a recurring item in your calendar and you should be all set.

It’s a similar situation with vendor prefixes. Vendor prefixes were never intended to be a long-lasting part of any style sheet. Like polyfills, they’re supposed to be used with an exit strategy in mind: when the time is right, remove the prefixed styles, leaving only the unprefixed standardised CSS. Again, that’s a lot easier to do if you’re working on a product and you know that you’ll be the one revisiting the CSS later on. That’s harder to do at an agency where you’re handing over CSS to someone else.

I’m quite reluctant to use any vendor prefixes at all—which is at should be; vendor prefixes should not be used lightly. Sometimes they’re unavoidable, but that shouldn’t stop us thinking about how to remove them at a later date.

I’m mostly just thinking out loud here. I guess my point is that certain front-end development techniques and technologies feel like they’re better suited to product work rather than agency work. Although I’m sure there are plenty of counter-examples out there too of tools that really fit the agency model and are less useful for working on the same product over a long period.

But even though the agency world and the product world are very different in lots of ways, both of them require us to think about the future. How will long will the code you’re writing today last? And do you have a plan for when it needs updating or replacing?

Responses

3 Shares

# Shared by Jason Pamental on Friday, October 3rd, 2014 at 4:49pm

# Shared by Scott Jehl on Friday, October 3rd, 2014 at 4:49pm

# Shared by Todd Parker on Friday, October 3rd, 2014 at 5:48pm

13 Likes

# Liked by Mat Marquis on Friday, October 3rd, 2014 at 5:47pm

# Liked by Ethan Marcotte on Friday, October 3rd, 2014 at 5:47pm

# Liked by Matt Steele on Friday, October 3rd, 2014 at 6:02pm

# Liked by Scott Jehl on Friday, October 3rd, 2014 at 6:02pm

# Liked by Alex Morris on Friday, October 3rd, 2014 at 6:02pm

# Liked by Max Fenton ✰ on Friday, October 3rd, 2014 at 6:02pm

# Liked by Tom Leadbetter on Friday, October 3rd, 2014 at 6:14pm

# Liked by Anne Petersen on Friday, October 3rd, 2014 at 9:01pm

# Liked by Todd Parker on Friday, October 3rd, 2014 at 9:02pm

# Liked by James Drinkwater on Friday, October 3rd, 2014 at 9:12pm

# Liked by Marc Drummond on Saturday, October 4th, 2014 at 3:14am

# Liked by Matt Stow on Saturday, October 4th, 2014 at 1:12pm

# Liked by Jonathan Dallas on Sunday, October 5th, 2014 at 6:00pm

Related posts

Mind the gap

If you’re making a library or framework, treat it like a polyfill.

CSS Day 2024

A genuinely inspiring event.

Displaying HTML web components

You might want to use `display: contents` …maybe.

Progressive disclosure defaults

If you’re going to toggle the display of content with CSS, make sure the more complex selector does the hiding, not the showing.

event.target.closest

DOM scripting and event handling.

Related links

How we think about browsers | The GitHub Blog

JavaScript doesn’t get executed on very old browsers when native syntax for new language features is encountered. However, thanks to GitHub being built following the principle of progressive enhancement, users of older browsers still get to interact with basic features of GitHub, while users with more capable browsers get a faster experience.

That’s the way to do it!

Concepts like progressive enhancement allow us to deliver the best experience possible to the majority of customers, while delivering a useful experience to those using older browsers.

Read on for the nitty-gritty details…

Tagged with

Modern CSS in a Nutshell - Cloud Four

I like this high-level view of the state of CSS today. There are two main takeaways:

  1. Custom properties, flexbox, and grid are game-changers.
  2. Pre- and post-processers are becoming less and less necessary.

This is exactly the direction we should be going in! More and more power from the native web technologies (while still remaining learnable), with less and less reliance on tooling. For CSS, the tools have been like polyfills that we can now start to remove.

Alas, while the same should be true of JavaScript (there’s so much you can do in native JavaScript now), people seem to have tied their entire identities to the tooling they use.

They could learn a thing or two from the trajectory of CSS: treat your frameworks as cattle, not pets.

Tagged with

The Simplest Way to Load CSS Asynchronously | Filament Group, Inc.

Scott re-examines the browser support for loading everything-but-the-critical-CSS asynchronously and finds that it might now be as straightforward as this one declaration:

<link rel="stylesheet" href="/path/to/my.css" media="print" onload="this.media='all'">

I love the fact the Filament Group are actively looking at how deprecate their loadCSS polyfill—exactly the right attitude for polyfills in general.

Tagged with

10 things I learned making the fastest site in the world

Behind the amusing banter there’s some really solid performance advice in here. Good stuff.

Client Side Rendering (CSR), or as I call it “setting money on fire and throwing it in a river” has its uses, but for this site would have been madness.

Tagged with

Popover API Sliding Nav

Here’s a nifty demo of popover but it’s not for what we’d traditionally consider a modal dialog.

Tagged with

Previously on this day

12 years ago I wrote Scrollin’, scrollin’, scrollin’

Keep them updates scrollin’.

17 years ago I wrote España

Next stop: Asturias.

20 years ago I wrote Earth shattering

My brother-in-law lives and works in Seattle. That’s his workplace they’re talking about in this article in this Newsweek article about Starbucks.

21 years ago I wrote Liggin'n'giggin

I’m feeling a bit fragile today after a somewhat hedonistic night out.

23 years ago I wrote Tony comes to Brighton

Tony Blair was in Brighton today for the Labour party conference. Here’s the full text of his speech. It’s pretty stirring stuff although mentioning Europe right now smacks a little of opportunism. Overall, a good speech from a great speaker.

23 years ago I wrote The W3C Patent Policy

The World Wide Web Consortium has come under a lot of fire recently for burying a proposal that would allow its recommendations to be released under a fee-paying licence.