So if you load up the website, you would literally see one element called Santa app. Now, it turns out we found this to be a bit of an anti pattern. We find that web components work best when they're kind of compartmentalized things that used, or discrete elements that represent a single unit of work that can be tested and kind of used very easily. We found that just writing regular JavaScript to orchestrate a few elements was much better than writing one monolithic element.
Secondly, one thing I want to call out, we often use HTML because it's semantic. We use header and section because that has meaning to us as developers and to people looking at our pages using screen readers. Now I can create an element called fancy link, but maybe I shouldn't because turns out, browsers don't understand that, right? They understand A to mean link. Now, you can work around this. You can construct your element with A elements, but it's worth considering and keeping in mind, but before you just dive in and want to replace everything that HTML gives you for free.
So I'd like to use a concrete example of divs versus semantic elements. Now, using divs like this isn't really ideal. Although I suspect Gmail is targeting these divs, rather than building them by hand. The class names there are pretty gross. They do actually have some semantic meaning here. So here is a role equals main hidden within this big, massive layout. But to me, if I was writing a Gmail equivalent site, I think maybe I would use things like headers, navs, some built-in elements, along with a bunch of custom elements, that really provide some semantic meaning. You know, we've got this search icon here. We've got this compose button, and then individual messages. And to me, like as a developer, this seems like a much nicer way to build the site. This is obviously up to you, but this is one of the ways you can use web components. And you might imagine building a site like this. Fundamentally, though, web components are here now, right? You see them all over the place, you probably have used them without even realizing. For Santa Tracker, our big use case here is to drive the shell and the kind of layout of the site. We've actually got a lot of old code, and those games live within iframes, and often, you know, 10-plus-year-old code that's built with jQuery, and they're a whole mess. It's one of the powers of the web, right? Like, I don't have to change that code dramatically, but we do have to support it. But all the new stuff is all web components, which has made the developing for the site really quite a delight. We also see some really interesting use cases out there on the web. GitHub somewhat semi-famously shipped dates down to the client as, like, 2021-05-5. What they then do at runtime is they have a web component which turns that absolute date into a relative date. This is actually really cool because you can actually cache that page almost forever, and then at runtime, the web component is going to replace that absolute time with a relative time.
Comments