5

Why Salesforce has introduced new feature called Lightning Web Component (LWC)? What is the benefit over Lightning Component?

I have went through various blogs to find out the actual need of LWC over Lightning Component. Is it something doing same thing in new way?

3
  • 2
    Christophe Coenrats' introductory blog post is pretty explicit on the benefits. Standards compliance, performance, interoperability, and so forth. Is there a specific aspect you're seeking more detail on?
    – David Reed
    Dec 24, 2018 at 19:55
  • 2
    @codeyinthecloud Hahaha, I thought this looked familiar.
    – sfdcfox
    Dec 24, 2018 at 20:05
  • 1
    @sfdcfox I remembered your answer on the other one the moment I saw this! Dec 24, 2018 at 20:31

1 Answer 1

11

LWC is meant to be a Lightning Components 2.0. It has a lot of pretty nice features.

Knowledge Domain

Developers familiar with Web Components are mostly familiar with LWC out-of-the-box. Aura is proprietary, so the more you know about web standards, the more you'll have of a skill that can be used outside Salesforce, too!

Better Execution

LWC leverages built-in browser security features from WC standards, so there's less custom code. This means they run faster and are more consistent in how they enforce security. Also, events have a more limited scope, so there's much less processing required to handle events.

New Security Features

We get better CSS isolation, script isolation, DOM isolation, and a more limited event scope, all of which leads to more consistent component design.

ES6+

We now have better support for ES6 and ES7, not available in Aura. You can do more in less code. It also transpiles code to work with IE 11 and other browsers that are missing some features.

More Consistent Data Binding

Two-way data binding, which has always been kind of buggy in Aura, is gone. This forces developers to coordinate how data moves between components. This also means that data binding will work as expected, without the "gotchas" from Aura.

Service Components

You can now write components that have no UI. They simply provide reusable methods that you can use in other components. This is much more efficient than Static Resources.

Mixins

You can import accessible methods from other components (as per above), and also import specific Apex methods, even from multiple classes. In addition, the Apex methods can be cached for improved performance.


Basically, LWC was a way for salesforce.com to fix all the things that were "not quite right" about Aura, while also moving towards web standards. There's no imperative to switch, as both style components are largely compatible with each other, although there's some restrictions to where and how they can be used.

Your Aura skills won't be lost, and you will keep using them (LWC isn't supported in a lot of ways that ISVs and Developers want), but the widgets and so on that make up your Aura components can benefit from using LWC, in terms of performance and security enhancements.

3
  • can you tell me a little about service components, Is this something in the documentation?
    – d_k
    Feb 15, 2019 at 4:51
  • 2
    @d_k They are briefly mentioned in the docs. Perhaps the most relevant is here: Every UI component must have an HTML file with the root tag <template>. Service components (libraries) don’t require an HTML file. There's another mention in the next topic "Component JavaScript File" as well.
    – sfdcfox
    Feb 15, 2019 at 4:58
  • 2
    @d_k Basically, if you don't define a myComponent.html file, you've created a service component. You can import methods and variables that have been exported, which you can then call from other components. There's two examples in the lwc-recipes repo under mortgage and miscSharedJavaScript.
    – sfdcfox
    Feb 15, 2019 at 4:59

Not the answer you're looking for? Browse other questions tagged .