Skip to content

Instantly share code, notes, and snippets.

@misode
Created May 6, 2022 23:43
Show Gist options
  • Save misode/96ab245eb89ba67465963ae9f377608c to your computer and use it in GitHub Desktop.
Save misode/96ab245eb89ba67465963ae9f377608c to your computer and use it in GitHub Desktop.

Optimizing and code-splitting

I decided to investigate the bundle size for misode.github.io and was quite shocked. After code splitting and tree shaking I managed to get the total JS output size from 5.22MB down to 3.95MB, and the main entrypoint from 4.53MB down to 703KB.

Initial bundle

The initial bundle was 5.22MB, with the main chunk 4.53MB (the red part). The only chunks split up were the different languages localizations. image

Remove unused highlight.js languages

One of the first things I noticed was that highlight.js included a bunch of languages, while I'm only using JSON. This eliminated 1.35MB. image

Split mcschema versions

Most visitors will only need one version of mcschema. Each version is about 200KB large. With those split off, the main chunk was reduced from 3.17MB to 2MB. image

Brace editor

The next library is brace, which is the JSON text editor. This is quite a large library: 742KB. While it's used on every generator page (when highlighting is enabled), I decided to split it anyways. image

Deepslate

Deepslate is the library used for the worldgen visualizers. Evidently it's only used on those generator pages and when the visualizer is active.

However the deepslate imports are intertwined with the website code, so splitting would not be easy. Instead I decided to split off the duplicate version of deepslate for 1.18 (before 1.18.2), which is 300KB. image

Sourcemapped stacktrace

This is a library only used when an error is detected and I want the stacktrace remapped to create a link to github issues. This only needs to be loaded once an error appears. image

JSON with comments

The generator allows pasting JSON with comments. For this I use comment-json, which again is quite a large library: 400KB. image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment