anki icon indicating copy to clipboard operation
anki copied to clipboard

Consider lazy-loading MathJax and CodeMirror in editor

Open dae opened this issue 2 years ago • 3 comments

MathJax appears to account for about 1/3rd of our (2.9MB large!) editor bundle, and codemirror appears to be the second-largest contributor. If we were able to lazy-load these as required, we may be able to improve editor startup time for users who don't use MathJax or the HTML editor by default. We're also using the full MathJax bundle - maybe there's a way to lazy-load the required parts? A good starting point would be to just strip them out and compare editor loading time before and after, to see what sort of performance gains there are.

dae avatar Jul 01 '23 00:07 dae

AnkiDroid simply searches for \(, \), \[ or \] in card's template before deciding to load MathJax.

The majority of MathJax extensions are lazy-loaded by default unless autoload is disabled. mchem should be safe to remove from https://github.com/ankitects/anki/blob/78b4a391cc9bf3a127fe3a11984bff75b909b136/ts/mathjax/index.ts#L6 noerrors and mathtools however, are not autoloaded.

nihil-admirari avatar Jul 03 '23 16:07 nihil-admirari

@dae Should this issue be closed? The last PR was merged and @nihil-admirari 's comment seems to address the concerns.

KurtPrice avatar Aug 29 '25 06:08 KurtPrice

I guess initializing MathJax conditionally can still be useful to speed up the editor if it's never used. CodeMirror will also need to be investigated.

abdnh avatar Sep 02 '25 18:09 abdnh