Skip to content

Commit 5b74253

Browse files
authored
Load mermaid asynchronously (#13778)
If mermaid is synchronously loaded, a slow load can prevent the sidebar navigation from displaying. Instead, we load mermaid asynchronously and then call `mermaidLoaded()` when it loads.
1 parent 66f0bd0 commit 5b74253

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/elixir/scripts/elixir_docs.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@ canonical = System.fetch_env!("CANONICAL")
189189
before_closing_body_tag: fn
190190
:html ->
191191
"""
192-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js"></script>
193192
<script>
194-
document.addEventListener("DOMContentLoaded", function () {
193+
function mermaidLoaded() {
195194
mermaid.initialize({
196195
startOnLoad: false,
197196
theme: document.body.className.includes("dark") ? "dark" : "default"
@@ -209,8 +208,9 @@ canonical = System.fetch_env!("CANONICAL")
209208
preEl.remove();
210209
});
211210
}
212-
});
211+
}
213212
</script>
213+
<script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js" onload="mermaidLoaded();"></script>
214214
"""
215215

216216
_ ->

0 commit comments

Comments
 (0)