15 Hiding your complexities
This chapter closes the book by arguing that the real power of Web Components is their ability to hide internal complexity behind simple, stable interfaces. After a bumpy standards journey (for example, HTML Imports fading out), the fundamentals are now broadly supported and unlikely to change soon. The author highlights upcoming HTML and CSS modules, shadow parts/themes, and design-system-friendly styling as the next big enablers, alongside a growing ecosystem of framework-agnostic tools. The message: encapsulation keeps components usable for years, regardless of the implementation details inside.
To illustrate, the chapter explores demanding domains where encapsulation shines. In 3D, VR, and AR, low-level WebGL and sensor fusion are daunting, yet higher-level approaches like A-Frame (with nonvisual, scene-defining tags) and Google’s model-viewer offer simple markup for complex scenes, interaction, and even AR handoffs. The author then builds a custom 3D scene component with Babylon.js, wiring cameras, lights, materials, and UI (like a color picker) into a single, easy-to-use element. Across these examples, components act as boundaries that separate intricate rendering and math from everyday page code.
The chapter then moves to live video effects and machine learning. A video component abstracts camera setup and frame access, first demonstrating CPU-based pixel filters and then upgrading to GPU-accelerated WebGL shaders for performance and custom effects. Finally, a hand-tracking component wraps a Tensorflow.js-based model, emitting high-level events that are effortlessly integrated into the earlier Web Harp app. The takeaway is consistent: by encapsulating complexity—graphics, performance, computer vision, or ML—Web Components make advanced functionality approachable, reusable, and future-proof, while keeping the core standards (and developer experience) simple.
Example A-Frame scene
Inspecting the A-Frame scene
Changing A-Frame objects live in the browser’s dev tools
Astronaut model over a colored background
Poly search component with model-viewer preview
Example AR glasses field of view
Placing a virtual object in the real world using ARCore
A 3D color picker application
3D color picker project structure
A live video stream with a black and white filter
Live camera feed with “snow” effect
Edge detection effect with a WebGL-based video Web Component
Radial fade around edges of a live camera feed
Handtracker Web Component demo
Web Harp with hand tracking
Summary
In this chapter, you learned
- What may happen in the Web Component future
- How Web Components can make intimidating technologies like mixed reality and machine learning approachable
- Hiding your own complex systems, like a full 3D scene in a Web Component
- Leveraging components created throughout this book for emerging technologies
Web Components in Action ebook for free