Introducing LWC - Lightning Web Components
Tags: lwc, webcomponents
Published: 2020-02-01 20:06:32

---
title: Introducing LWC - Lightning Web Components
published: true
date: 2020-01-08 17:57:00 UTC
tags: lwc,web components
canonical_url: https://blog.riand.com/2020/01/introducing-lwc-lightning-web-components.html
---

[![](https://1.bp.blogspot.com/-SgEgl_mvceU/Xh84R-T7frI/AAAAAAAAA0g/LeguRKrk27oSGbBVRrULWoTW4MOxn9hZwCLcBGAsYHQ/s320/lightning-web-components.png)](https://1.bp.blogspot.com/-SgEgl_mvceU/Xh84R-T7frI/AAAAAAAAA0g/LeguRKrk27oSGbBVRrULWoTW4MOxn9hZwCLcBGAsYHQ/s1600/lightning-web-components.png)

  
  
In the previous [post](https://dev.to/philriand/the-rise-of-web-components-1iie-temp-slug-5711248), I talked about Web Components in general. But Salesforce released at [TrailheadDX 2019](https://www.salesforce.com/company/news-press/press-releases/2019/05/192915-e/) a new open source technology called Lightning Web Components, aka [LWC](https://lwc.dev/). Basically, LWC is a set of tools, including a compiler, a runtime engine, some build utilities that you can use to create both reusable components and applications.  

## Why a tool for creating Web Components?
Actually, Web Components are defined through a set of new browser specifications, so they don't require any framework. There are many examples showing how to create such reusable components just using the bare APIs!  
  
If this is correct, you'll quickly find out that these APIs are very low level. As a result, creating an even moderately complex component requires a bunch of boilerplate code: you need to maintain the synchronization between HTML attributes and JavaScript properties, you need to keep the DOM up-to-date on data changes, ... and many other boring stuff!  
  
That's the reason why several technologies appeared in the past years: they provide you an easier experience with Web Components. They are kind of lightweight frameworks on top of the Web Components APIs. They are often called "invisible" frameworks as, once the components are created, the technology used to create the components is not apparent. As a consumer of the components, you don't really care what has been used behind the scene to create them.  

## What does LWC bring on the table?

**Enterprise ready** 

LWC is an enterprise ready technology, designed to support Salesforce business in the long term. When I think about it, I can find a lot of similarities between [Salesforce](https://www.salesforce.com/) and [Lotus/IBM](https://en.wikipedia.org/wiki/Lotus_Software): my latest [Notes](https://en.wikipedia.org/wiki/IBM_Notes) client can still execute applications from the '90, and so Salesforce can execute apps built with older releases (or seamlessly convert them). Such a backward compatibility is critical for businesses! It is even more emphasized with cloud architectures, as the customers are upgraded automatically without the choice to stay on an older release. From an LWC standpoint, it means that every feature added to the tool will have to be supported "forever" and thus is carefully evaluated with a risk assessment. Any new feature has to go through an RFC, see: [lwc-rfcs](https://github.com/salesforce/lwc-rfcs). 
  

**ES6+/Typescript**

We are in 2020 now, I can't see myself back using ES5 and JQuery. I believe you're on the same boat! LWC eases the use of ES6+, making your code future proof even when staging features like [decorators](https://tc39.es/proposal-decorators/) are involved. It is using [Babel](https://babeljs.io/) behind the scene, for which [Salesforce Engineering](https://engineering.salesforce.com/) is a proud sponsor.

  

**Browser support **

If the latest "evergreen" browsers natively support the Web Components specification, older browsers should  use polyfills and/or the compiler should generate specific code for these browsers. LWC does a bit of both, including some tailored polyfills to achieve performance goals. [@lwc/synthetic-shadow](https://www.npmjs.com/package/@lwc/synthetic-shadow) is a good example of such a polyfill.

  

**Templating**

LWC provides a template engine that renders markup from an HTML template. Somehow, it is similar to [lit-html](https://lit-html.polymer-project.org/guide), except that it is compiled to Javascript at build time, for a faster execution. In that respect, it is similar to the [JSX compiler](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx).

  

**Reactivity**

If the template syntax supports one-way data binding, the component reactivity comes from [observable-membrane](https://github.com/salesforce/observable-membrane), which is another Salesforce open source project. In a nutshell, it allows objects to be observed for changes. Typically, Components are redrawn when at least one of their properties is changed (can be the root property, or another object referenced by that property).

  

**Data Binding**

Associated with the above membrane is the notion of wire adapters. Basically, a wire adapter streams data to a component and makes it re-render when needed. It can be used similarly to [React hooks](https://reactjs.org/docs/hooks-intro.html). More information here: [wire adapters,](https://github.com/salesforce/lwc-rfcs/blob/master/text/0103-wire-adapters.md) superseded by the [wire-reform.](https://github.com/salesforce/lwc-rfcs/blob/master/text/0000-wire-reform.md)

  

**Performance**  

Performance is a key characteristic of LWC. It is constantly, and deeply, tuned to provide the best client side performance.

  

**Static analysis**  
For advanced users, the LWC compiler can be used to extract meta-data from the components. For example, a plugin could extract the data sources being accessed and generate some initialization code.  

  

And several others, like matching attribute and properties, ...: a set of goodies that makes your life easier as a developer! 

## The flavors of LWC

Well, if there is one LWC technology, there are two deployments:

- Salesforce platform  
The Salesforce platform handles many things for free, like the LWC compilation, so you don't have to manage rollup/webpack builds, nor you have to maintain package.json. On the other hand, it runs within the constraints of the Salesforce platform, including [Locker](https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/security_code.htm) and other differences.
- Open source, aka LWC OSS ([Github](https://github.com/salesforce/lwc))  
LWC can be used similarly to any other Javascript technology. To get started, you can use the nice [lwc-create-app](https://github.com/muenzpraeger/create-lwc-app) tools from [Rene Winkelmeyer (](https://twitter.com/muenzpraeger?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor)[@muenzpraeger](https://twitter.com/muenzpraeger)[)](https://twitter.com/muenzpraeger?ref_src=twsrc%5Egoogle%7Ctwcamp%5Eserp%7Ctwgr%5Eauthor), that some of you know from our prior IBM life.  
This is LWC unleashed!
The differences are detailed [here](https://developer.salesforce.com/blogs/2019/06/differences-between-building-lightning-web-components-on-lightning-platform-and-open-source.html), thanks again to Rene.  

## And what next?

Now that I introduced the LWC technology (I hope it got you hooked!), it is time to get our hands dirty. I'm not going to provide any tutorial or getting started document because they already exist. I'll rather focus on some specific aspect of Web Components and LWC.

  

By the meantime, you can get started here: [Introducing Lightning Web Components](https://developer.salesforce.com/docs/component-library/documentation/lwc) or here: [lwc.dev.](https://lwc.dev/)