Streamlining HTML web components

If you’re a front-end developer and you don’t read Chris Ferdinandi’s blog, you should change that right now. Add that RSS feed to your feed reader of choice!

Lately he’s been posting about some of the thinking behind his Kelp UI library. That includes some great nuggets of wisdom around HTML web components.

First of all, he pointed out that web components don’t need a constructor(). This was news to me. I thought custom elements had to include this incantation at the start:

constructor () {
  super();
}

But it turns that if all you’re doing is calling super(), you can omit the whole thing and it’ll be done for you.

I immediately refactored all the web components I’m using on The Session. While I was at it, I implemented Chris’s bulletproof web component loading.

Now technically, I don’t need to do this. I’m linking to my JavaScript at the bottom of every page so I know it’s going to load after the HTML. But I don’t like having that assumption baked into my code.

For any of my custom elements that reference other elements in the DOM—using, say, document.querySelector()—I updated the connectedCallback() method to use Chris’s technique.

It turned out that there weren’t that many of my custom elements that were doing that. Because HTML web components are wrapped around existing markup, the contents of the custom element are usually what matters (rather than other elements on the same page).

I guess that’s another unexpected benefit to HTML web components. Because they’ve already got their own bit of DOM inside them, you don’t need to worry about when you load your markup and when you load your JavaScript.

And no faffing about with the dark arts of the Shadow DOM either.

Have you published a response to this? :

Responses

Doug Parker

Thanks for sharing this, it reminds me a lot of hydration timing issues I’ve been experimenting with. youtu.be/euFQRqrTSMk?… (~12 min in is the relevant bit.) I feel like making an HTML web component active after its DOM is loaded is very similar in concept to hydrating that component.

Doug Parker

I suspect using init to wait on document ready could create similar file ordering issues to what I describe in the video. I actually have a community protocol proposal which kind of helps codify the defer-hydration pattern in this context. github.com/webcomponent…

Doug Parker

Also this reminds me how generally inadequate web components APIs are for streaming use cases, since you can’t wait for a specific element to be done parsing and it’s naturally incompatible with DSD. blog.dwac.dev/posts/stream…

Jeff Bridgforth

I added an “on this day” to my blog archive page that you can click on. It is mostly for me because I determined that I am my main audience so I am making it easy for me to find things. :)

Matthias Ott

Great! 👏 The problem with “on this day” on my site would be that my post frequency hasn’t been high enough to make that a useful feature. It would probably not show anything at all most of the time… 😅

3 Shares

# Shared by Dawn Ahukanna on Tuesday, July 22nd, 2025 at 1:18pm

# Shared by benoit.kogut on Tuesday, July 22nd, 2025 at 1:49pm

# Shared by Sue on Tuesday, July 22nd, 2025 at 5:26pm

10 Likes

# Liked by Quincy - he/him on Tuesday, July 22nd, 2025 at 11:20am

# Liked by Cameron Wardzala 🇺🇦 on Tuesday, July 22nd, 2025 at 11:34am

# Liked by Marcus Herrmann on Tuesday, July 22nd, 2025 at 11:34am

# Liked by Dawn Ahukanna on Tuesday, July 22nd, 2025 at 11:34am

# Liked by Jordi Sánchez on Tuesday, July 22nd, 2025 at 11:53am

# Liked by Robin on Tuesday, July 22nd, 2025 at 11:53am

# Liked by benoit.kogut on Tuesday, July 22nd, 2025 at 1:49pm

# Liked by Florian Geierstanger on Tuesday, July 22nd, 2025 at 3:56pm

# Liked by Sue on Tuesday, July 22nd, 2025 at 5:26pm

# Liked by Intellog Inc. on Tuesday, July 22nd, 2025 at 7:34pm

1 Bookmark

# Bookmarked by Brent Lineberry on Wednesday, July 23rd, 2025 at 6:26pm

Related posts

Announcing Web Day Out

A one-day event all about what you can in web browsers today: Brighton, March 12th, 2026. Tickets are just £225+VAT!

Command and control

HTML’s new `command` attribute on the `button` element could be a game-changer.

Manual ’till it hurts

Try writing your HTML in HTML, your CSS in CSS, and your JavaScript in JavaScript.

Lost in calculation

A lazy option for responsive images is at hand.

Multi-page web apps

A question via email…

Related links

Close to the metal: web design and the browser

It seems like the misguided perception of needing to use complex tools and frameworks to build a website comes from a thinking that web browsers are inherently limited. When, in fact, browsers have evolved to a tremendous degree

Tagged with

Snook Dreams of the Web - Snook.ca

If we were to follow Jiro’s and his apprentices’ journeys and imagine web development the same way then would we ask of our junior developers to spend the first year of their career only on HTML. No CSS. No JavaScript. No frameworks. Only HTML. Only once HTML has been mastered do we move onto CSS. And only once that has been mastered do we move onto JavaScript.

Tagged with

Building WebSites With LLMS - Jim Nielsen’s Blog

And by LLMS I mean: (L)ots of (L)ittle ht(M)l page(S).

I really like this approach: using separate pages instead of in-page interactions. I remember Simon talking about how great this works, and that was a few years back, before we had view transitions.

I build separate, small HTML pages for each “interaction” I want, then I let CSS transitions take over and I get something that feels better than its JS counterpart for way less work.

Tagged with

5 Questions for Jeremy Keith · Frontend Dogma

If you like the prospect of an old man ranting at clouds, this is for you.

Tagged with

Tagged with

Previously on this day

5 years ago I wrote Wildlife Photographer Of The Year on the Clearleft podcast

The third episode is a case study—and what a case study!

11 years ago I wrote Adactibots

Replicating my URL structure on Twitter.

11 years ago I wrote Indie Web Camp Brighton

Right after dConstruct.

18 years ago I wrote Macback

I got my laptop back just in the nick of time.

21 years ago I wrote Mother London

I was in London yesterday for a meeting with one of Semantico’s clients.

22 years ago I wrote Wireless Workshop

I’m sitting downstairs in the Grand Central pub in Brighton enjoying the bandwidth.

22 years ago I wrote Redesigning Ben Hammersley

Seeing as I can’t afford a Volkswagen (not to mention the fact that I can’t even drive), I’m trying to get my hands on an iPod by other means.