Skip to content

Commit

Permalink
load stylesheet and javascript script from remote location
Browse files Browse the repository at this point in the history
  • Loading branch information
FabienArcellier committed Oct 2, 2023
1 parent deb2eff commit 7463e57
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions ui/src/core_components/CoreRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,23 @@ function handleHashChange() {
}
async function importStylesheet(stylesheetKey: string, path: string) {
const req = await fetch(path);
if (req.status > 399) {
console.warn(`Couldn't import stylesheet at "${path}".`);
return;
}
const existingEl = document.querySelector(`[data-streamsync-stylesheet-key="${stylesheetKey}"]`);
existingEl?.remove();
const el = document.createElement("style");
const el = document.createElement("link");
el.dataset.streamsyncStylesheetKey = stylesheetKey;
const cssText = await req.text();
el.textContent = cssText;
document.head.appendChild(el);
el.setAttribute('href', path)
el.setAttribute("rel", "stylesheet");
document.head.appendChild(el);
}
async function importScript(scriptKey: string, path: string) {
const req = await fetch(path);
if (req.status > 399) {
console.warn(`Couldn't import script at "${path}".`);
return;
}
const existingEl = document.querySelector(`[data-streamsync-script-key="${scriptKey}"]`);
existingEl?.remove();
const el = document.createElement("script");
el.dataset.streamsyncScriptKey = scriptKey;
const scriptText = await req.text();
el.textContent = scriptText;
document.head.appendChild(el);
el.src = path;
el.setAttribute("rel", "modulepreload");
document.head.appendChild(el);
}
async function importModule(moduleKey: string, specifier: string) {
Expand Down

0 comments on commit 7463e57

Please sign in to comment.