bricks_load_custom_cdn
Phase 4.5IntermediateComplexity: 4/10
Load any custom CSS/JS from a CDN URL
Overview
Loads a custom CSS or JS file from any CDN URL. Use this when the library you need is not in the built-in catalog. Injects the appropriate <link> or <script> tag and optional initialization code.
Key Features
Any CDN URL
Load any CSS or JS from any HTTPS CDN URL
Deduplication
Checks for existing URLs before injecting
Init script support
Optional initialization JS wrapped in DOMContentLoaded
When to Use
Loading a library not in the built-in catalog
Adding a specific version of a library
Injecting custom CSS/JS from a third-party CDN
Adding a specific version of a library
Injecting custom CSS/JS from a third-party CDN
Prerequisites
Have the full CDN URL ready (must start with https://)
Know the asset type (css or js)
Know the asset type (css or js)
When NOT to Use
For libraries in the built-in catalog — use bricks_load_cdn_library instead (handles URLs automatically)
For inline custom code — use bricks_add_custom_css or bricks_add_custom_js
For inline custom code — use bricks_add_custom_css or bricks_add_custom_js
Parameters
5 Total Parameters2 Required3 Optional
urlstringREQUIREDFull CDN URL (must start with https://)
typeenumREQUIREDAsset type: css or js
Values:
css, jsscopeenumoptionalWhere to inject: global or page
Default:
global Values: global, pagepage_idnumberoptionalPage ID (required for page scope)
init_scriptstringoptionalOptional init JS to run after load
Code Examples
Load a custom JS library
Load a library from a CDN with initialization
JSON
{
"url": "https://cdn.example.com/lib.min.js",
"type": "js",
"scope": "global",
"init_script": "MyLib.init({ option: true });"
}Response
{"success": true, "actions": ["✓ Injected JS into global footer", "✓ Injected init script into global footer"]}Tips & Warnings
Tips & Warnings
- URL must be HTTPS — HTTP URLs are not supported
- CSS is injected in the header, JS in the footer with
defer - Init scripts are wrapped in
DOMContentLoadedautomatically
Return Values
Related Tools
Technical Details
Changelog
v1.0
Initial release
20250101