Is it possible to get code from cdn instead of npm?

Has anyone tried something like this ?

function loadProseMirrorLibraries({ package, version }) {
  const js = document.createElement("script");
  js.type = 'text/javascript';
  js.src = `${package}@:${version}`;

  js.onload = () => {
    // Do something
  { package: 'prosemirror-state', version: '1.0.0' },
  { package: 'prosemirror-view', version: '1.0.0' },

Because I don’t want to increase my bundle size by hundreds of kilo bytes, so I’m trying to find alternative ways of importing the ProseMirror libraries, if you guys have any experiences of doing it, could you let me know how it went ?


You might want to look into ‘code splitting’, which is a feature in bundlers where they dynamically load some dependencies.

Thanks for your advise, but unfortunately our app is completely SPA, so code splitting may not solve the issue for us.

But I just tried to pull the code from, which contains anything I need, and I can play with it very well without troubles.

Code splitting should work fine with single page apps. But anyway, be aware that if you end up hotlinking the script on my site and generating non-trivial bandwidth use, you’re likely to get blocked. (Though maybe you just meant you copied the script?)

Thanks, I will have another look at how to do code splitting with SPA. (I thought I had to build the bundle to be able to import those packages, instead of loading them in the runtime.)

Also yeah, I use it as a temporary solution, will eventually try to find better alternatives. ( Code splitting could be the one, also copy the whole scripts .)