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.

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

Speaking at Web Day Out

Have you got the perfect talk for this event? Let me know!

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.

Related links

The Great CSS Expansion | Butler’s Log

Web development follows a familiar cycle. First we glue together a solution with whatever we have — JavaScript, image hacks, Flash, anything. Then the platform matures, and CSS or HTML eventually makes that same workaround native. Rounded corners, custom fonts, smooth scrolling, sticky positioning: all of these started as JavaScript-heavy hacks before CSS turned them into a single declaration.

We are in another one of those transition moments. A new wave of long-requested CSS features is finally landing, and many of them are explicitly designed to replace patterns that used to require JavaScript. Not as approximations — as first-class platform primitives that handle the edge cases, run in the right thread, and need zero dependencies.

Tagged with

Performance-Optimized Video Embeds with Zero JavaScript – Frontend Masters Blog

This is a clever technique for a CSS/HTML only way of just-in-time loading of iframes using details and summary.

Tagged with

Reduce the JS Workload with no- or lo-JS options

This is an excellent one-stop shop of interface patterns:

This is an organic collection of common JS patterns that can be replaced with just HTML, CSS, and no, or very low, JS. As HTML and CSS continue to mature, this collection should expand.

Tagged with

699: Jeremy Keith on Web Day Out – ShopTalk

This episode of the Shop Talk Show is the dictionary definition of “rambling” but I had a lot of fun rambling with Chris and Dave!

Tagged with

Tagged with

Previously on this day

6 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!

12 years ago I wrote Adactibots

Replicating my URL structure on Twitter.

12 years ago I wrote Indie Web Camp Brighton

Right after dConstruct.

19 years ago I wrote Macback

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

22 years ago I wrote Mother London

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

23 years ago I wrote Wireless Workshop

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

23 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.