How do I use static resources in Salesforce?

How do I use static resources in Salesforce?

Use the $Resource global variable and the URLFOR() function to reference items within a zipped static resource. The URLFOR() function can combine a reference to a zipped static resource and a relative path to an item within it to create a URL that can be used with Visualforce components that reference static assets.

What is static resource in Salesforce?

Static resources allow you to upload content that you can reference in a Visualforce page, including archives (such as .zip and .jar files), images, style sheets, JavaScript, and other files. Static resources can be used only within your Salesforce org, so you can’t host content here for other apps or websites.

What can static resources be used for in Salesforce?

Static resources can be used only within your Salesforce org, so you can’t host content here for other apps or websites. Using a static resource is preferable to uploading a file to the Documents tab because: You can package a collection of related files into a directory hierarchy and upload that hierarchy as a .zip or .jar archive.

How to use static resources in Visualforce developer guide?

Using Static Resources 1 You can package a collection of related files into a directory hierarchy and upload that hierarchy as a .zip or .jar… 2 You can reference a static resource by name in page markup by using the $Resource global variable instead of hard coding… More

Why do we use static resources in JavaScript?

In addition, using static resources to refer to JavaScript or cascading style sheets (CSS) is preferable to including the markup inline. Managing this kind of content using static resources allows you to have a consistent look and feel for all your pages and a shared set of JavaScript functionality.

When to create a stand alone static resource?

Create a simple, stand-alone static resource for independent static assets. When your static asset is not related to other assets—that is, not part of a set of similar assets such as a group of icons—it’s easiest to create a stand-alone static resource.