Skip to content

Commit

Permalink
Load mermaid asynchronously (#13778)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
voughtdq authored Aug 13, 2024
1 parent 66f0bd0 commit 5b74253
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/elixir/scripts/elixir_docs.exs
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ canonical = System.fetch_env!("CANONICAL")
before_closing_body_tag: fn
:html ->
"""
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
function mermaidLoaded() {
mermaid.initialize({
startOnLoad: false,
theme: document.body.className.includes("dark") ? "dark" : "default"
Expand All @@ -209,8 +208,9 @@ canonical = System.fetch_env!("CANONICAL")
preEl.remove();
});
}
});
}
</script>
<script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js" onload="mermaidLoaded();"></script>
"""

_ ->
Expand Down

0 comments on commit 5b74253

Please sign in to comment.