Why are Web Components interesting?

rrees

Robert Rees

Posted on March 11, 2024

Why are Web Components interesting?

I've been increasingly interested in Web Components and trying to understand how I can rewrite my historic code to use this standard. Most developers I talk to though are pretty much frontend===React: what is this strange thing you're talking about?

The dominance of virtual DOM frontends with complex lifecycles and associated tool chains means that people have invested a lot of intellectual and emotional effort into these tools and genuinely think they are the best way to deliver web experiences to people. This post is not going to change their views and I think it is genuinely hard to do that. Enterprise computing is probably going to be using React, Angular and other frameworks for a while yet.

If you are not particularly wedded to a particular frontend approach then Web Components have a few things that make them interesting. Firstly, they are standards compliant. They are available in all browsers, work consistently and require no libraries, bundles or WASM compilers to run. It is easier to re-use Web Components because of this standards approach as the baseline functionality is clear across all deployments. This simply isn't true of VueJS and React. When you make a choice of what is essentially a mini-language you are then stuck in that ecosystem with no shared runtime. Weirdly I've seen Web Components used as bridge between different components in production and it actually worked quite well, allowing different rendering and event handling approaches but co-ordinating state.

Web Components offer the opportunity to try and get back to progressively enhanced experiences that with reduced dependency on virtual rendering and Javascript could be more sustainable. They are easy to add on top of regular HTML and seem to fail with more safety than virtual rendering which tends to completely fail on a problem leaving a blank page or component.

The final thing that is interesting is that Web Components are a lower-power solution, they literally just allow you to create new elements and encapsulate behaviour. They are not also trying to provide a styling, state or templating solution so you are able to compose them with other technologies. Some people like ShadowDOM, some don't but by having smaller modules of standards-based behaviour people can use a common-base to take different approaches.

If you haven't looked at Web Components it doesn't take long to work through the basics and I would really recommend knowing them alongside any preferred virtualised framework you may have learnt or used day to day.

💖 💪 🙅 🚩
rrees
Robert Rees

Posted on March 11, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Why are Web Components interesting?
javascript Why are Web Components interesting?

March 11, 2024