Static resources in Visualforce, LWC and Aura
Why files belong in static resources (name-based references, zip hierarchies, the content security policy, caching) and the exact reference syntax in each technology: $Resource and URLFOR in Visualforce, @salesforce/resourceUrl and platformResourceLoader in LWC, $Resource concatenation and ltng:require in Aura.
Describe the purpose and benefit of static resources in Visualforce, Lightning Web Components, and Aura Components.
~7 min read · 7 practice questions ·
What the exam expects
- Explain why static resources beat the Documents tab, inline scripts and hardcoded IDs, and what they can't do (host content outside the org).
- Reference a standalone file and a file inside a zip archive in Visualforce, a Lightning web component and an Aura component.
- Load a third-party JavaScript library from a static resource with
loadScript()/loadStyle()in LWC andltng:requirein Aura, at the right point in the lifecycle. - Apply the size limits and choose Private or Public cache control.
Key terms: static resource (an uploaded file or archive referenced by name), archive static resource (a .zip or .jar whose internal folders are addressed by path), $Resource (the Visualforce global variable and the Aura global value provider for static resources), @salesforce/resourceUrl (the LWC scoped module that imports a resource URL), cache control (Private per session or Public shared cache).
Key facts
- Detail
- 5 MB per static resource; 250 MB per org
- Detail
- Usable only within your org; can't host content for other sites
- Detail
- Cached only for the current user's session, not shared
- Detail
- Shared cache, faster loads; open to all internet traffic once cached
- Detail
URLFOR($Resource.name, 'path/file')
- Detail
import X from '@salesforce/resourceUrl/name', then concatenate a path
- Detail
$Resource.name + '/path/file'; no URLFOR
loadScript() and loadStyle()- Detail
- Return promises; first argument must be
this
ltng:require timing- Detail
- Use
afterScriptsLoaded, notinit
- Detail
ltng:requireplusloadScript()on one URL loads it twice
Sources for this section (6)
- Using Static Resourcesdeveloper.salesforce.com (opens in a new tab)
- Access Static Resourcesdeveloper.salesforce.com (opens in a new tab)
- Referencing a Static Resource in Visualforce Markupdeveloper.salesforce.com (opens in a new tab)
- $Resourcedeveloper.salesforce.com (opens in a new tab)
- Platform Resource Loaderdeveloper.salesforce.com (opens in a new tab)
- Using External JavaScript Librariesdeveloper.salesforce.com (opens in a new tab)
- Why is a zip static resource better than files on the Documents tab for Visualforce pages deployed to several orgs?
- When should an Aura component call a library loaded by `ltng:require`?
- Why does a Lightning web component load a charting library in `renderedCallback()` instead of `connectedCallback()`?
- What are the size limits for static resources?
The questions are free to read. Answers with their sources and self-grading are included with the pack.
Keep reading with the Platform Developer II pack
- Core concepts
- Exam traps
- Worked scenario
The pack includes:
- All 28 lessons of the Platform Developer II guide, with reading progress
- Interactive decision walks and step-by-step sequence steppers
- Inline practice questions and one-click topic practice (7 questions for this lesson)
- An official source cited for every claim
- An AI tutor that answers from the guide
- Unlimited timed practice exams