The Good, The Bad, and The Web Components

Spanish audio is available in the player settings
Rate this content
Bookmark

There has been no shortage of both fair and unfair criticism toward Web Components from a wide range of folks that build for the web, including but not limited to JavaScript Framework authors in supposed competition with the platform. In this talk I'll show you how to navigate and simplify the multifaceted landscape of web components, satisfying common criticisms and showing how you can Use the Platform most effectively today.

This talk has been presented at JSNation 2023, check out the latest edition of this JavaScript Conference.

FAQ

Web Components are reusable pieces of UI that are enabled by web standards and built into the web platform. They are provided by web browsers and help in initializing components faster with less library overhead.

The benefits of using Web Components include faster component initialization, reduced library overhead, and the ability to create reusable and portable UI components that are integrated directly into the web platform.

The hyphen in Web Component tag names is required to avoid conflicts with existing and future HTML elements. It ensures that custom element names do not collide with standard HTML elements, which do not use hyphens.

Declarative Shadow DOM is a specification that allows the browser to handle the templating and shadow DOM injection automatically, reducing the dependency on JavaScript for initializing Web Components while maintaining encapsulation and style scoping.

Server-Side Rendering in the context of Web Components refers to the ability to render components on the server, improving performance by reducing the amount of JavaScript needed on the client-side and enhancing the initial page load time.

The future of Web Components involves enhancing their compatibility with SSR and streaming capabilities, making them more efficient and reducing duplication in component instances, thus optimizing both loading times and development practices.

Yes, several major companies use Web Components, including Microsoft (MSN), VMware, Google (Material Design), IBM, Salesforce, GitHub, and Adobe (Photoshop on the web using Lit).

To create a Web Component, you define a custom element by specifying a tag name and associating it with a class. The custom element registry then enhances or hydrates these elements when encountered by the browser.

ShadowDOM provides a way to encapsulate styles and markup in web components, ensuring styles and scripts do not leak into the global environment. It allows components to include styles scoped only to them without affecting other parts of the page.

As of April of the reported year, nearly 19 percent of page loads in the Google Chrome web browser were properties using Web Components, indicating their significant popularity.

Zach Leatherman
Zach Leatherman
29 min
01 Jun, 2023

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Web Components are a piece of reusable UI enabled by web standards and built into the web platform. They offer the potential for faster component initialization and less library overhead. Web Components can be created from scratch and utilized with existing component libraries. Shadow DOM and Declarative Shadow DOM provide benefits such as scoped CSS and server-rendered components. The tradeoff between not repeating oneself and achieving full server-side rendering support is discussed. User experience is deemed more important than developer experience.

1. Introduction to Web Components

Short description:

Today we're going to talk about web components. They're good. They're bad. Hopefully, not ugly. Here is an example of a component. Look at that. It's a button. We have our nice JavaScript up top. We have our JSX on the bottom. Some of you might be familiar with what this example comes from. It's from Vercell.js. There's a ton of component abstractions that exist in the space. But today I want to talk to you about Web Components.

How's everybody doing? Got some coffee? Bruce, I guess we're old friends. Great. That's awesome to hear. Well, you couldn't really tell by that introduction, but that's fine. Bruce and I get along really good.

All right. So today we're going to talk about web components. They're good. They're bad. Hopefully, not ugly. So, yes. Web components. Animations. Gotta love it. Web components, right? I don't have to convince you all that components are good, right? Components. Yay.

All right. Here is an example of a component. Look at that. It's a button. Woo-hoo! Thank you. That's been my time. Yeah. So we have our nice JavaScript up top. We have our JSX on the bottom. This is great. And some of you might be familiar with what this example comes from. It's from Vercell.js.

So if we look at some of the other component libraries that exist right now, there's a ton of them, right? There's a ton of component abstractions that exist in the space. But today I want to talk to you about Web Components.

2. Web Components and Design Systems

Short description:

Web Components are a piece of reusable UI enabled by web standards and built into the web platform. They offer the potential for faster component initialization and less library overhead. Examples of Web Components in use include MSN, material design, and Adobe Photoshop on the web. According to Google Chrome's Web Statistics, nearly 19 percent of page loads in the browser utilize Web Components.

So Web Component is a piece of reusable UI, it's enabled by web standards. It's built into the web platform. It's provided to you for free by web browsers. And really the benefit here is you have the potential to initialize your components faster and run with less library overhead, which is great.

So as Bruce introduced, my name is Zach. I blog on zackleet.com. I built Eleventy, which is a static site generator. And I work at Netlify. And just to kind of convince you that Web Components are a thing that you should care about, I'm going to show you some examples. Hooray. This is peer pressure. This is social proof. And after these four or five slides, you all are going to be convinced that Web Components are amazing. So let's get into it.

Web Components, really the bread and butter of Web Components right now is design systems. People love the portability of Web Components. They love that they're built into the platform. And that's really where the most examples you'll see of them are in the wild. Microsoft built MSN with Web Components. VMware has a nice design system. Google has material design which exports to Web Components. IBM has one, Salesforce. My personal favorite, Nord Health built with 11-D is a really good example of that. GitHub uses Web Components. Adobe actually brought Photoshop to the Web with Web Components using Lit, which I think is great. And that's using Spectrum Web Components which is a wrapper around Lit. So are Web Components a thing? Look at all these logos, logos, logos, logos. We love logos. Does that really convince us that things are good? Yes, I think so. If you go out to Google Chrome's Web Statistics, they have as of April of this year, measured that 18, almost 19 percent of page loads in the Google Chrome Web Browser are properties using Web Components.

QnA

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

It's Time to De-Fragment the Web
React Day Berlin 2022React Day Berlin 2022
34 min
It's Time to De-Fragment the Web
Top Content
Today's Talk introduces Mitosis, an open source project that solves the problem of building framework agnostic components. It supports JSX and Svelte syntax and outputs human-readable code for various web frameworks. Mitosis is already being used by enterprise customers and can be easily integrated with React, Svelte, and other frameworks. It saves time, allows for easy handling of framework version migrations, and enables efficient unit and integration testing.
Web Components, Lit and Santa 🎅
JSNation Live 2021JSNation Live 2021
28 min
Web Components, Lit and Santa 🎅
Web Components and the Lit library are introduced, highlighting their ability to create custom elements and replicate built-in components with different functionality. The use of semantic HTML and the benefits of web components in development are emphasized. The features of Lit, such as data binding and rendering, are discussed. The Santa Tracker is showcased as an example of web components being used in educational games. The compatibility of web components with other frameworks and their versatility in creating small widgets or large applications are highlighted.
Authoring HTML in a JavaScript World
React Summit US 2023React Summit US 2023
21 min
Authoring HTML in a JavaScript World
Watch video: Authoring HTML in a JavaScript World
This Talk by Tony Alicia focuses on authoring HTML in a JavaScript world. The speaker challenges developers to change their approach to building React components by starting with HTML first. By authoring HTML in a semantic way, readability and maintainability can be improved. Well-authored HTML provides better understanding of content and improves accessibility. It also has performance benefits by reducing DOM size. Investing time in HTML can save time and make applications more future-proof.
Immutable Web Apps
JSNation 2022JSNation 2022
20 min
Immutable Web Apps
Today's Talk discusses immutable web apps and their benefits, such as faster loading times and easy version tracking. The use of Universal Module Definition (UMD) style bundling allows for flexible dependency management and gradual upgrades. Tools like Webpack and Rollup provide ways to reference UMDs in bundles and automate dependency configuration. Arborist and YAML files help resolve dependency trees and handle conflicts, while the Orchard CLI tool automates dependency ordering. Internal and external dependencies can be initialized and managed effectively for optimal performance.
Web Components are awesome!
JSNation 2022JSNation 2022
10 min
Web Components are awesome!
Web components allow you to create your own HTML elements that can do anything you want, and they are supported by all modern browsers. Many companies, including YouTube and GitHub, use web components to enhance their websites. There are extensive tooling and libraries available for web component development. The Model Viewer Web Component enables the display of 3D models in Virtual and Augmented Reality without needing to know underlying technologies. Web components can be used with various frameworks and libraries, and there are resources available to help with compatibility.
Let's talk about Web Components
React Advanced 2021React Advanced 2021
32 min
Let's talk about Web Components
Web Components are a suite of technologies that allow you to create reusable HTML elements, combining the fun of React with regular HTML. Custom elements and the shadow DOM are key features of Web Components, allowing you to define new elements, encapsulate functionality and styles, and interact with a separate DOM. HTML templates serve as placeholders for content to be rendered later in custom components. Custom elements and HTML templates are cross-framework compatible and can be used in React, Angular, Vue, or any other framework.

Workshops on related topic

Web Components in Action
JSNation Live 2021JSNation Live 2021
184 min
Web Components in Action
Workshop
Joren Broekema
Alex Korzhikov
2 authors
The workshop extends JavaScript programming language knowledge, overviews general software design patterns. It is focused on Web Components standards and technologies built on top of them, like Lit-HTML and Lit-Element. We also practice writing Web Components both with native JavaScript and using Lit-Element. In the end we overview key tooling to develop an application - open-wc.