sphinxcontrib-mermaid icon indicating copy to clipboard operation
sphinxcontrib-mermaid copied to clipboard

Defer javascript load

Open chrisjsewell opened this issue 2 years ago • 1 comments

Heya, at the moment the javascript load blocks the initial page render.

This is acutely problematic, if for example unpkg.com is being slow, as I just experienced in the MyST documentation 😒

You need to add the loading_method="defer": https://www.sphinx-doc.org/en/master/extdev/appapi.html#sphinx.application.Sphinx.add_js_file

You then need to account for this in the initialisation, something like:

window.onload = function () {mermaid.initialize({startOnLoad:true})}

Ideally even, I see that you use html-page-context to load the JS, but here you should also only load it on pages where mermaid is actually used

chrisjsewell avatar Feb 21 '23 12:02 chrisjsewell

+1 would love to see this fixed!

Belmogodx avatar Feb 28 '23 21:02 Belmogodx