Sub topic 2
Aura Sites Versus LWR Sites
This chapter assumes you can build a basic Lightning web component (HTML template, JavaScript class, meta file), read Apex and SOQL, and use the Salesforce CLI in a DX project. It compares the two site runtimes so you can pick one and know which component features carry over.
Two runtimes, one product name
Experience Cloud sites run on one of two runtimes. Both let you drop Lightning web components onto pages in Experience Builder. They differ in how they load pages, which features they support, and how your components behave at runtime.
- Aura sites are built on the Aura framework. They are the older runtime and support the widest set of Salesforce features, including the standard templates such as Customer Service and Partner Central.
- LWR sites use Lightning Web Runtime. They are built on Lightning Web Components only, with no Aura framework underneath. They emphasize fast page loads, content delivery through a CDN, and publish-based versioning.
The runtime is chosen when you create the site, by picking a template. Switching a site from one runtime to the other later is not supported, so treat the choice as permanent. Moving to the other runtime means building a new site and rebuilding or re-pointing the pages.
How the runtimes load a page
The most useful mental model is where the work happens.
An Aura site renders pages in the browser through the Aura framework. Your LWC sits inside an Aura page, and data requests go to the server as the user navigates. Pages are served from the Salesforce platform and are not versioned as a published snapshot in the way LWR sites are.
An LWR site publishes a snapshot of the site. Visitors receive pre-built resources, which can be cached at the edge. The runtime loads only the modules a page needs. Changes you make in Experience Builder do not reach visitors until you publish.
Comparing the two
| Area | Aura site | LWR site |
|---|---|---|
| Component model | LWC and Aura components | LWC only |
| Template choice | Many standard templates | Fewer templates, such as Build Your Own (LWR) |
| Publishing | Live changes are saved and published through Builder | Changes are published as a versioned snapshot |
| Delivery | Served from the platform | Served with CDN caching |
| Security model | Lightning Locker or Lightning Web Security, depending on org setting | Lightning Web Security |
| Context imports | Many `@salesforce/*` imports available | Support for some imports differs |
| Navigation | `NavigationMixin` with Aura-style page references | `NavigationMixin` with LWR-supported page references |
| Feature coverage | Broadest | Narrower, growing over time |
Feature coverage changes with each Salesforce release. Before committing to a runtime, check the current Experience Cloud documentation for the features you need, such as specific standard components, search, or CMS connect support.
What changes for your components
The meta file, the JavaScript class, and the Apex controller from earlier chapters mostly work in both runtimes. Four areas need attention.
Targets
A component is exposed to Experience Builder through targets in its meta file. The two targets used in this tutorial are lightningCommunity__Page and lightningCommunity__Default. These work for both runtimes. The first makes the component available in the page editor. The second lets you define properties that the editor shows.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>60.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Case List</masterLabel>
<targets>
<target>lightningCommunity__Page</target>
<target>lightningCommunity__Default</target>
</targets>
<targetConfigs>
<targetConfig targets="lightningCommunity__Default">
<property name="maxRows" type="Integer" default="5" label="Maximum rows" />
</targetConfig>
</targetConfigs>
</LightningComponentBundle>A component that targets only lightningCommunity__Page appears in the editor but has no configurable properties. Without isExposed set to true, it does not appear at all.
Aura wrappers
In an Aura site you can wrap a component in an Aura component if you need an Aura-only capability, such as an Aura event or an interface that LWC does not offer. This is not possible in LWR, where no Aura framework exists. If your plan depends on Aura wrappers, that is a reason to stay with an Aura site.
Imports and context
Imports such as @salesforce/user/isGuest give your component information about the current visitor. Many are available in both runtimes, but support for some site-specific imports, such as certain community and site identifiers, differs. Test each import you use in the runtime you choose rather than assuming it works.
import { LightningElement, api, wire } from 'lwc';
import isGuest from '@salesforce/user/isGuest';
import getMyCases from '@salesforce/apex/CaseListController.getMyCases';
export default class CaseList extends LightningElement {
@api maxRows = 5;
isGuest = isGuest;
@wire(getMyCases, { maxRows: '$maxRows' })
cases;
get hasCases() {
return Boolean(this.cases && this.cases.data && this.cases.data.length);
}
}This component works in both runtimes because it uses only the isGuest import, a wired Apex method, and a public property.
Navigation
Both runtimes support NavigationMixin. Page reference types that point to Aura-specific constructs, such as standard__namedPage names that exist only in Aura templates, may not resolve in LWR. Record pages and comm__namedPage references are the safest choices.
import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';
export default class CaseLink extends NavigationMixin(LightningElement) {
handleClick(event) {
this[NavigationMixin.Navigate]({
type: 'standard__recordPage',
attributes: {
recordId: event.currentTarget.dataset.id,
objectApiName: 'Case',
actionName: 'view'
}
});
}
}Choosing a runtime
Decide with a short list of questions.
- Do you need a standard template or a feature that exists only in Aura sites? If yes, use Aura.
- Do you depend on Aura components, Aura wrappers, or Aura events? If yes, use Aura.
- Is page speed for anonymous traffic the priority, and are your needed features available in LWR? If yes, consider LWR.
- Do you want a versioned publish step so edits stay hidden until you release them? LWR provides this.
- Are you starting new and your component library is all LWC? LWR is a reasonable default if the feature check passes.
Run the feature check first, because a missing feature found late is costly. The runtime cannot be changed on an existing site.
Common errors
- Component missing from the editor. Check that
isExposedistrue, that the target is listed, and that the component deployed to the org. Then reload Experience Builder. - Property not shown in the editor. The
propertymust be inside atargetConfigwhosetargetsattribute nameslightningCommunity__Default. - Works in Aura, fails in LWR. The usual causes are an unsupported import, an Aura dependency, or a page reference type that LWR does not resolve. Read the browser console and compare with the documented limits.
- Edits not visible to visitors in LWR. The site was not published. Publish after each set of changes you want visitors to see.
- Stale behavior after deployment. Cached assets can hide a new component version. Publish again and test in a private browser window.
Exercise
A team needs a partner portal that uses a standard Aura template and an existing Aura component with Aura events. Another team wants a fast public marketing site built only with LWC and published as a versioned snapshot. Which runtime fits each team, and why?
Show answer
The partner portal fits an Aura site, because it needs a standard Aura template and Aura components and events, which LWR does not support. The marketing site fits an LWR site, because it is LWC-only and benefits from CDN delivery and publish-based versioning. Each team should confirm that the features it needs exist in its runtime before creating the site, since the runtime cannot be changed later.
Exercise
Your meta file lists only the lightningCommunity__Page target and defines a maxRows property in a targetConfig for lightningCommunity__Default. The component appears in Experience Builder, but no maxRows field shows. What do you change?
Show answer
Add lightningCommunity__Default to the <targets> list. The target configuration applies only to targets that the component declares, so without it the editor does not show the property.