Skip to content

Options Reference

All options are passed as the second argument to include(). Every option is optional.

OptionTypeDefaultDescription
logLevel'silent' | 'warn' | 'verbose''warn'Logging verbosity
timeoutnumber10000Load timeout in milliseconds
retriesnumber0Retry attempts on failure
retryDelaynumber1000Milliseconds between retries
maxConcurrencynumber3Max simultaneous loads
prioritynumber0Load order priority (higher = first)
cacheBustingbooleanfalseAppend cache-busting query string
cacheBustingQuerystring'?_=<timestamp>'The query string to append
cacheBustingTypesstring[]['js', 'css']File types to apply cache busting
restrictCacheBustingToLocalbooleantrueOnly bust cache for same-origin URLs
onSuccessfunctionPer-resource success callback
onErrorfunctionPer-resource error callback
appendToBodybooleanfalseAppend scripts to <body>
deferScriptsUntilReadybooleantrueDefer scripts until DOMContentLoaded
removeFailedElementsbooleantrueRemove DOM elements on failure
crossoriginfalse | 'anonymous' | 'use-credentials'falsecrossorigin attribute value
attributesobject{}Additional element attributes

Type: 'silent' | 'warn' | 'verbose' Default: 'warn'

Sets the logging verbosity for this call. Also updates the global level for subsequent calls.

ResourceLoader.include([url], { logLevel: 'verbose' });

See setLoggingLevel() for more details.


Type: number (milliseconds) Default: 10000

Maximum time to wait for a resource to load. If the timeout is exceeded, the load is aborted with error.type === 'timeout'. Each resource and each retry attempt gets its own independent timeout clock.

ResourceLoader.include([url], { timeout: 5000 }); // 5 seconds

Type: number Default: 0

Number of additional attempts after the first failure. A value of 3 means 4 total attempts (1 initial + 3 retries).

ResourceLoader.include([url], { retries: 3 });

Type: number (milliseconds) Default: 1000

Time to wait between retry attempts. Requires retries > 0 to have any effect.

ResourceLoader.include([url], { retries: 2, retryDelay: 2000 });

Type: number Default: 3

Maximum number of resources that load simultaneously. Additional resources queue and start as slots become available.

ResourceLoader.include(manyUrls, { maxConcurrency: 5 });

Type: number Default: 0

Sort order for the load queue. Higher numbers load before lower numbers. Sorting happens across separate include() calls before the concurrency queue runs.

// These load before lower-priority calls
ResourceLoader.include([critical], { priority: 10 });
ResourceLoader.include([analytics], { priority: 0 });

Type: boolean Default: false

When true, appends a cache-busting query string to resource URLs (subject to cacheBustingTypes and restrictCacheBustingToLocal).

ResourceLoader.include([url], { cacheBusting: true });
// URL becomes: https://example.com/app.js?_=1710000000000

Type: string Default: '?_=<timestamp>'

The query string to append when cacheBusting is enabled. Override this to use a version number or content hash instead of a timestamp.

ResourceLoader.include([url], {
cacheBusting: true,
cacheBustingQuery: '?v=2.1.0',
});

Type: string[] Default: ['js', 'css']

File extensions that receive the cache-busting query string when cacheBusting is true.

ResourceLoader.include([url], {
cacheBusting: true,
cacheBustingTypes: ['js', 'css', 'json'],
});

Type: boolean Default: true

When true, cache busting is only applied to URLs that share the same origin as the current page. Set to false to apply it to all URLs, including external CDNs.

ResourceLoader.include([url], {
cacheBusting: true,
restrictCacheBustingToLocal: false, // Apply to CDN URLs too
});

Type: function Default: none

Callback invoked once per resource as each one finishes loading. The argument varies by resource type:

Resource typeArgument
JS, CSS, imagesURL string
JSONParsed JavaScript object
Audio, video, PDF, binaryBlob object
Fontsundefined
ResourceLoader.include([url], {
onSuccess: (data) => {
if (typeof data === 'string') console.log('Loaded URL:', data);
else if (data instanceof Blob) console.log('Loaded blob:', data.type);
else console.log('Loaded data:', data);
},
});

Type: function Default: none

Callback invoked when a resource fails (after all retries are exhausted). Receives two arguments:

  • error: { type: 'network' | 'timeout' | 'abort' | 'unsupported', message: string }
  • url: The URL that failed
ResourceLoader.include([url], {
onError: (error, url) => {
console.error(`[${error.type}] ${url}: ${error.message}`);
},
});

Type: boolean Default: false

When true, <script> elements are appended to <body> instead of <head>. Has no effect on CSS, JSON, or other types.

ResourceLoader.include(['https://cdn.example.com/app.js'], {
appendToBody: true,
});

Type: boolean Default: true

When true, script elements are not inserted until the DOMContentLoaded event has fired. If the DOM is already ready when include() is called, this has no visible effect.

ResourceLoader.include([url], { deferScriptsUntilReady: false });

Type: boolean Default: true

When true, failed <script>, <link>, and <img> elements are removed from the DOM automatically. Set to false to leave them for debugging.

ResourceLoader.include([url], { removeFailedElements: false });

Type: false | 'anonymous' | 'use-credentials' Default: false

Sets the crossorigin attribute on <script> and <link> elements. Required when using Subresource Integrity (attributes.integrity).

ResourceLoader.include([url], {
crossorigin: 'anonymous',
attributes: { integrity: 'sha384-...' },
});

Type: object Default: {}

Additional HTML attributes to apply to the created DOM element. The most commonly used attribute is integrity for SRI:

ResourceLoader.include(['https://cdn.example.com/lib.js'], {
crossorigin: 'anonymous',
attributes: {
integrity: 'sha384-abc123...',
// Any other valid attribute for the element type:
// nonce: 'abc123',
// referrerpolicy: 'no-referrer',
},
});