Agenda
This blog gives us a brief about how we can use Static resources inside a Lightning Web Component and use it over the Javascript as well as access it over the HTML.
What we are going to do
In this blog, we are going to upload 4 different pictures of the sun from different timings into the static resources of our org, and then we use that static resource into our Lightning Web Component and display the images according to our system timezones.
Lightning Web Component
Lightning Web Components is lightweight and delivers exceptional performance. Most of the code you write is standard JavaScript and HTML.
Static Resources
Static resources allow you to upload content that you can reference on a Visualforce page, Visualforce Component, Lightning Component (both Aura Component and Lightning Web Component), including archives (such as .zip and .jar files), images, style sheets, JavaScript, and other files.
Import static resources from the @salesforce/resourceUrl scoped module.
Ways to import Static resource over the component:
import myResource from '@salesforce/resourceUrl/resourceReference';
import myResource from '@salesforce/resourceUrl/namespace__resourceReference';
myResource—A name that refers to the static resource.
resourceReference—The name of the static resource.
namespace—If the static resource is in a managed package, this value is the namespace of the managed package.
Scenario:
Here I am import 4 static resources one is main frame and other 3 are the frame which are going to display according to system timings.
Expected outcome:
HTML Syntax:
JavaScript Syntax:
CSS Syntax:
Resulted Outcome:
A static resource can be an archive file with a nested directory structure.To reference a resource in a template, use {property} syntax, which is the same syntax you use to reference any JavaScript property.
A single static resource can be up to 5 MB in size. An organization can have up to 250 MB of static resources. Static resources apply to your organization’s quota of data storage.
Limitations of this blog:
The blog is limited to this 4 static resource files and for the fixed timings as described, if you need more dynamic, you need to more more over the dynamics of the code, and the styling of the code may be differe from org to org, page to page, computer pixels to pixels. So, you need to be more careful over the styling part.
Blog’s Conclusion:
This blog gives us a brief about how we can use Static resources inside a Lightning Web Component and use it over the Javascript as well as access it over the HTML.



Great
ReplyDelete