Skip to content

Commit db887c8

Browse files
committed
Extract module script sources for deferred loading by router
1 parent 994dd8f commit db887c8

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

public/js/main.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,11 @@ async function loadPage(url) {
127127
// Create a temporary div to hold the content
128128
const tempDiv = document.createElement('div');
129129

130-
// Automatically detect and import module scripts
131-
await componentLoader.detectAndImportModules(doc);
130+
// Extract module script sources (they'll be loaded later by the router)
131+
const moduleScripts = componentLoader.extractModuleScriptSources(doc);
132+
console.log('Extracted module scripts:', moduleScripts);
132133

133-
// Filter out script tags (they'll be imported dynamically)
134+
// Filter out script tags (they'll be imported dynamically by the router)
134135
const contentWithoutScripts = componentLoader.filterScriptTags(doc.body, true); // Keep script tags
135136
content = contentWithoutScripts.innerHTML;
136137
}

public/js/router.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ async function loadPage(url) {
4040
const parser = new DOMParser();
4141
const doc = parser.parseFromString(html, 'text/html');
4242

43-
// Import any modules
44-
await componentLoader.detectAndImportModules(doc);
43+
// Extract module script sources (they'll be loaded later by the router)
44+
const moduleScripts = componentLoader.extractModuleScriptSources(doc);
45+
console.log('Extracted module scripts in router.js:', moduleScripts);
4546

4647
// Execute any inline scripts
4748
await componentLoader.executeInlineScripts(doc);

0 commit comments

Comments
 (0)