My Tiptap plugin needs to load a ton of scripts. I now allow users to dynamically choose which functionalities they want to use – however I still load all the libraries. I’m looking to optimize that by loading only the requested libraries.
I looked around MDN and peered into @keith’s Loaderr plugin. I got it to work with this code
const s = document.createDocumentFragment();
const e = document.createElement("script");
e.type = 'module';
e.innerText = `import { Editor } from "https://esm.sh/@tiptap/core";window.tiptapEditor = Editor;`;
s.appendChild(e)
const createdScript = document.head.appendChild(s)
On the browser’s console, I can see window.tiptapEditor
so that works.
However, I can’t grab on to that inside the update
function in the plugin. If I try to console.log it, it shows up as undefined.
I’m guessing it’s a timing error – the script is not yet loaded when I call it right afterwards. I tried adding a e.onload
but that function never gets called.
Any ideas?