[Feature] Bundle the Monaco editor

Author: QbDesuCreated Jul 16, 2021Updated Dec 6, 2025
Labelsenhancement

Additional context I already started a stub of discussion on this on the Discord server, just putting it here for better organization and to get input from others on this too maybe

Describe the feature you'd like At the moment the files for the the Monaco editor - the editor used for CustomCSS and the built-in addon editor - is downloaded from the Cloudflare CDN on every client startup and is not shipped with BetterDiscord itself.

My proposal is bundling it with BetterDiscord for the following reasons:

The version of the library hosted on CDN versions uses AMD modules and not CommonJS modules or ES modules like the rest of the environment. As a result loading the editor requires some workarounds to get it's AMD loader to work without breaking stuff. This could be eliminated by bundling the ES modules which are also available instead.

For most - if not soon all users - it would have to be loaded anyway. Currently it only loads when CustomCSS is enabled, although it would also at the very least need to be loaded if the edit action for addons is set to "Detached Editor" as well to avoid #864. So it could save some traffic and have it load a bit quicker, while at the same time eliminating a point of failure by not depending on Cloudflare.

Bundling it would in turn increase the size of the BetterDiscord bundle, significantly so. The minified files of Monaco total at a little more than 1MB which is of course huge considering it's all code. This means the BetterDiscord asar would need slightly longer too load even if I'd venture a guess and say most user's wouldn't notice it. These files would otherwise need to be downloaded through the internet anyway, the networking adding to load times. The increased bundle size is made up for because it saves you'd have to download it sooner or later anyway, likely multiple times even.

On (slightly) increased intial startup times because the editor can't be loaded asynchronously. I'm not sure it would actually increase the time needed to start BD significantly for 2 reasons:

  1. I don't know if the method used currently will actually result in it being loaded asynchronously or just deferred, as the script tag added has no async attribute to indicate that it should be loaded asnychronously. So maybe it will just put it at the end of the current queue There may also be a rendering tick in that queue I don't know enough about any of this, If you know this stuff better I would appreciate if you could correct me if I'm wrong. https://github.com/BetterDiscord/BetterDiscord/blob/65dc214ffe083f89ab9f935a8420e6cc114ad27b/renderer/src/modules/dommanager.js#L92-L100
  2. The files are already local so there is no delay caused by network. And the bundled script can be read from the disk in a single contious read operation. So if it actually increased load times it may not be noticable at all.

The 2 above points not that much more than guesses and it would be best just to test it and see.

A way to load the editor deferred either way would be puting it in an asar electron archive file similar to emotes. But seeing that people have issues downloading the emotes.asar already and suspecting it will not add much value I would rather opt not to do that.

Source: BetterDiscord/BetterDiscord