-
Notifications
You must be signed in to change notification settings - Fork 0
3rd Party Resource Management
Brandon Jordan edited this page Sep 7, 2025
·
18 revisions
Spark has an abstraction for easily controlled resources designed to:
- Wait to load resources until the page loads.
- Conditionally load resources.
- Load resources later on to squeeze out the best initial page load time.
- Easily manage external resources.
There are 3 built-in types of resources:
JavaScriptResource(src, attrs = {})StylesheetResource(href, attrs = {})GoogleFontResource(name, weights = [400, 500, 600, 700])
All of these extend the Resource class. Each resource overrides the load() method to load its specific type of resource. The attrs are passed to an element() function and places the tag in the <head/>.
Resources are never loaded automatically. To load an individual resource or a manager's resources, call its load() method.
Provide resources to a ResourceManager:
const resources = new ResourceManager(
new JavaScriptResource(CDN_URL),
);Then when they are ready to be loaded:
resources.load();A resource manager can be also appended to and then loaded.
if(load_THIS_resource) {
resources.append(new JavaScriptResource(CDN_URL, {
crossOrigin: 'anonymous'
}));
}
resources.load();Each resource adds a tag to the document </head> using createResourceTag() which has a check to ensure that they do not reload the same resource twice.