Dynamic Library Loading
Dynamic library loading functionality for BetterForms - Load external JavaScript libraries, ESM modules, and CSS files from CDN dynamically within function actions.
Overview
Why Use This?
Quick Start
Load a UMD Library
// Load PapaParse from CDN
await BF.libraryLoadOnce('https://cdn.jsdelivr.net/npm/[email protected]/papaparse.min.js');
// Use it immediately
const result = Papa.parse('Name,Age\nJohn,30', { header: true });
console.log(result.data); // [{Name: "John", Age: "30"}]Load an ESM Module
Load CSS
API Reference
BF.libraryLoadOnce(url, options)
BF.libraryLoadOnce(url, options)Parameter
Type
Default
Description
BF.libraryIsLoaded(url)
BF.libraryIsLoaded(url)BF.libraryGetLoaded()
BF.libraryGetLoaded()Usage Examples
Example 1: Chart.js
Example 2: DayJS (ESM)
Example 3: Axios for API Calls
Example 4: Load with Security (SRI)
Example 5: Error Handling
Example 6: Multiple Libraries
Example 7: Dynamic Library Selection
ESM Module Scope
UMD vs ESM Behavior
Solution 1: Re-load in Each Action (Recommended)
Solution 2: Bind to Window (If Needed Globally)
Do You Even Need It Again?
Best Practices
β
DO:
β DON'T:
Supported Library Formats
β
UMD (Universal Module Definition)
β
ESM (ES Modules)
β
CSS Stylesheets
Finding CDN URLs
Step 1: Find the Package on npm
Step 2: Browse the CDN
Step 3: Verify the File Works
Troubleshooting 404 Errors
Real Examples
Common Libraries
Chart.js (Charting)
PapaParse (CSV Parser)
QRCode (QR Generator)
Axios (HTTP Client)
DayJS (ESM - Date Library)
Sortable.js (Drag & Drop)
Troubleshooting
Library Not Available After Loading
Timeout Error
CORS Error
Version Conflicts
See Also
Need Help?
Last updated
Was this helpful?