0

I have upload one CSS file in static resource may I know how can we refer it in Lightning Component ??

File Name uploaded as static Resource- bootstrap.css

Static Resource Name-CssFile

Also I have added the CSS code under style in component do i need to remove it. Please advise ??

1 Answer 1

1

In Aura, use ltng:require:

<ltng:require styles="{!$Resource.CssFile}" />

In LWC, use loadStyle:

import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
import STATIC_RESOURCE_NAME from '@salesforce/resourceUrl/CssFile';

// ... some time later ... //
loadStyle(this, STATIC_RESOURCE_NAME).then(
  () => {
    // do whatever you need to do after styles load
  }
)
3
  • Hi I also want to refer JS file , How can i do that scripts='/resource/Javascript' have added this code in Lightning Component but i got an error !! Javascrip is the static resource Name
    – user105921
    Commented Jan 19, 2022 at 12:28
  • Error i got -This page has an error. You might just need to refresh it. First, would you give us some details? (We're reporting this as error ID: -944567236!! Pls Help on this
    – user105921
    Commented Jan 19, 2022 at 12:51
  • @user105921 use {!$Resource.javascript}.
    – sfdcfox
    Commented Jan 19, 2022 at 13:23

You must log in to answer this question.

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