title: Extensibility
url: https://adactio.com/journal/8276
hash_url: 6cef4c24facfb5fd7a7f9049232b1a56

<p><a href="https://adactio.com/journal/7431">I’ve said it before</a>, but I’m going to reiterate my conflicted feelings about <a href="http://webcomponents.org/">Web Components</a>:</p>

<blockquote>
  <p>I have conflicting feelings about Web Components. I am simultaneously very excited and very nervous.</p>
</blockquote>

<p>There are broadly two ways that they could potentially be used:</p>

<ol>
<li>Web Components are used by developers to incrementally add more powerful elements to their websites. This evolutionary approach feels very much in line with the thinking behind <a href="https://extensiblewebmanifesto.org/">the extensible web manifesto</a>. Or:</li>
<li>Web Components are used by developers as a monolithic platform, much like Angular or Ember is used today. The end user either gets everything or they get nothing.</li>
</ol>

<p>The second scenario is a much more revolutionary approach—sweep aside the web that has come before, and usher in a new golden age of Web Components. Personally, I’m not comfortable with that kind of year-zero thinking. I prefer <a href="http://www.w3.org/TR/html-design-principles/#evolution-not-revolution">evolution over revolution</a>:</p>

<blockquote>
  <p>Revolutions sometimes change the world to the better. Most often, however, it is better to evolve an existing design rather than throwing it away. This way, authors don’t have to learn new models and content will live longer. Specifically, this means that one should prefer to design features so that old content can take advantage of new features without having to make unrelated changes. And implementations should be able to add new features to existing code, rather than having to develop whole separate modes.</p>
</blockquote>

<p>The evolutionary model is exemplified by the design of HTML 5.</p>

<p>The revolutionary model is exemplified by the design of XHTML 2.</p>

<p>I really hope that the Web Components model goes down the first route.</p>

<p>Up until recently, my inner Web Components pendulum was swinging towards the hopeful end of my spectrum of anticipation. That was mainly driven by the ability of <a href="http://www.w3.org/TR/custom-elements/">custom elements</a> to <a href="http://www.w3.org/TR/custom-elements/#type-extension-semantics">extend existing HTML elements</a>.</p>

<p>So, for example, instead of creating a new element like this:</p>

<pre><code>&lt;taco-button&gt;...&lt;/taco-button&gt;
</code></pre>

<p>…you can piggyback off the existing semantics of the <code>button</code> element like this:</p>

<pre><code>&lt;button is="taco-button"&gt;...&lt;/button&gt;
</code></pre>

<p>For a real-world example, see <a href="https://github.com/github/time-elements">Github’s use of <code>&lt;time is="time-ago"&gt;</code></a>.</p>

<p>I wrote about creating <a href="https://adactio.com/journal/7967">responsible Web Components</a>:</p>

<blockquote>
  <p>That means we can use web components as a form of progressive enhancement, turbo-charging pre-existing elements instead of creating brand new elements from scratch. That way, we can easily provide fallback content for non-supporting browsers.</p>
  
  <p>I’d like to propose that a fundamental principle of good web component design should be: “Where possible, extend an existing HTML element instead of creating a new element from scratch.”</p>
</blockquote>

<p>Peter Gasston also has a great post on <a href="http://www.broken-links.com/2015/01/27/best-practice-creating-custom-elements/">best practice for creating custom elements</a>:</p>

<blockquote>
  <p>It’s my opinion that, for as long as there is a dependence on JS for custom elements, we should extend existing elements when writing custom elements. It makes sense for developers, because new elements have access to properties and methods that have been defined and tested for many years; and it makes sense for users, as they have fallback in case of JS failure, and baked-in accessibility fundamentals.</p>
</blockquote>

<p>But now it looks like this superpower of custom elements is being <a href="https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0206.html">nipped in the bud</a>:</p>

<blockquote>
  <p>It also does not address subclassing normal elements. Again, while
  that seems desirable the current ideas are not attractive long term
  solutions. Punting on it in order to ship a v1 available everywhere
  seems preferable.</p>
</blockquote>

<p>Now, I’m not particularly wedded to the syntax of using the <code>is=""</code> attribute to extend existing elements …but I do think that the ability to extend existing elements declaratively is vital. I’m not alone, although I may very well be in the minority.</p>

<p>Bruce has <a href="https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0368.html">outlined some use cases</a> and Steve Faulkner <a href="https://lists.w3.org/Archives/Public/public-webapps/2015JanMar/0360.html">has enumerated the benefits of declarative extensibility</a>:</p>

<blockquote>
  <p>I think being able to extend existing elements has potential value to
  developers far beyond accessibility (it just so happens that  accessibility
  is helped a lot by re-use of existing HTML features.)</p>
</blockquote>

<p>Bruce concurs:</p>

<blockquote>
  <p>Like Steve, I’ve no particularly affection (or enmity) towards the
  <code>&lt;input type="radio" is="luscious-radio"&gt;</code> syntax. But I’d like to know, if it’s dropped, how progressive enhancement can be achieved so we
  don’t lock out users of browsers that don’t have web components
  capabilities, JavaScript disabled or proxy browsers. If there is a
  concrete plan, please point me to it. If there isn’t, it’s
  irresponsible to drop a method that we can see working in the example
  above with nothing else to replace it.</p>
</blockquote>

<p>He adds:</p>

<blockquote>
  <p>I also have a niggling worry that this may affect the uptake of web
  components.</p>
</blockquote>

<p>I think he’s absolutely right. I think there are many developers out there in a similar position to me, uncertain exactly what to make of this new technology. I was looking forward to getting really stuck into Web Components and figuring out ways of creating powerful little extensions that I could start using now. But if Web Components turn out to be an all-or-nothing technology—a “platform”, if you will—then I will not only <em>not</em> be using them, I’ll be actively arguing against their use.</p>

<p>I really hope that doesn’t happen, but I must admit I’m not hopeful—my inner pendulum has swung firmly back towards the nervous end of my anticipation spectrum. That’s because I’m getting the distinct impression that the priorities being considered for Web Components are those of JavaScript framework creators, rather than web developers looking to add incremental improvements while maintaining backward compatibility.</p>

<p>If that’s the case, then Web Components will be made in the image of existing monolithic MVC frameworks that require JavaScript to do anything, even rendering content. To me, that’s a dystopian vision, one I can’t get behind.</p>
