* Lazy load a full script when needed (on-demand loading) * @param {string} scriptId - The script ID * @returns {Promise } The full script object with all functions
(scriptId)
| 54 | * @returns {Promise<Object>} The full script object with all functions |
| 55 | */ |
| 56 | async function loadFullScript(scriptId) { |
| 57 | // Return from cache if already loaded |
| 58 | if (scriptCache.has(scriptId)) { |
| 59 | return scriptCache.get(scriptId); |
| 60 | } |
| 61 | |
| 62 | try { |
| 63 | // Dynamic import - only loads this one script |
| 64 | const module = await import(`../scripts/${scriptId}.js`); |
| 65 | const fullScript = module.default; |
| 66 | |
| 67 | // Inject the ID |
| 68 | fullScript.id = scriptId; |
| 69 | |
| 70 | // Cache for future use |
| 71 | scriptCache.set(scriptId, fullScript); |
| 72 | |
| 73 | return fullScript; |
| 74 | } catch (error) { |
| 75 | console.error(`Failed to lazy load script ${scriptId}:`, error); |
| 76 | throw error; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Preload popular/commonly used scripts in background |
no test coverage detected