Exploring ways to preserve the vanilla JS browser demo without compromising on the bundle. Experimenting with embedding images in the bundle as data URIs

This commit is contained in:
Rezmason
2025-05-06 12:59:02 -07:00
parent 6663c92f99
commit eea341f50c
27 changed files with 372 additions and 137 deletions

20
js/fetchLibraries.js Normal file
View File

@@ -0,0 +1,20 @@
export default async () => {
let glMatrix, createREGL;
try {
glMatrix = await import("gl-matrix");
createREGL = (await import("regl")).default;
} catch {
const loadJS = (src) =>
new Promise((resolve, reject) => {
const tag = document.createElement("script");
[tag.onload, tag.onerror, tag.src] = [resolve, reject, src];
document.body.appendChild(tag);
});
await Promise.all([loadJS("lib/regl.min.js"), loadJS("lib/gl-matrix.js")]);
glMatrix = globalThis.glMatrix;
createREGL = globalThis.createREGL;
}
return { glMatrix, createREGL };
};