add site-wide JS caching through import maps

This commit is contained in:
りき萌 2024-07-19 20:05:17 +02:00
parent f3aee8f41a
commit 10ccb250c1
15 changed files with 169 additions and 48 deletions

View file

@ -17,21 +17,6 @@ export const domConsole = {
}
};
async function withTemporaryGlobalScope(callback) {
let state = {
oldValues: {},
set(key, value) {
this.oldValues[key] = globalThis[key];
globalThis[key] = value;
}
};
await callback(state);
jsConsole.trace(state.oldValues, "bringing back old state");
for (let key in state.oldValues) {
globalThis[key] = state.oldValues[key];
}
}
let evaluationComplete = null;
export async function evaluate(commands, { error, newOutput }) {

View file

@ -1,7 +1,6 @@
// This is definitely not a three.js ripoff.
import { addSpell } from "treehouse/spells.js";
import { navigationMap } from "/navmap.js";
import * as ulid from "treehouse/ulid.js";
/* Branch persistence */
@ -128,7 +127,8 @@ class LinkedBranch extends Branch {
// No need to await for the import because we don't use the resulting module.
// Just fire and forger 💀
// and let them run in parallel.
import(script.src);
let url = URL.createObjectURL(new Blob([script.textContent], { type: "text/javascript" }))
import(url);
}
} catch (error) {
this.loadingText.innerText = error.toString();
@ -177,6 +177,8 @@ function navigateToPage(page) {
async function navigateToBranch(fragment) {
if (fragment.length == 0) return;
let { navigationMap } = await import("/navmap.js");
let element = document.getElementById(fragment);
if (element !== null) {
// If the element is already loaded on the page, we're good.