Skip to content

Commit 0dd9a77

Browse files
committed
Improve JS loading sequence
1 parent 7d3fbbd commit 0dd9a77

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

_includes/head.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
<script src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
6363

64-
<script async
64+
<script defer
6565
src="https://cdn.jsdelivr.net/combine/npm/popper.js@1.15.0,npm/bootstrap@4/dist/js/bootstrap.min.js"></script>
6666

6767
{% include js-selector.html %}

_includes/js-selector.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818

1919
{% if page.math %}
2020
<!-- MathJax -->
21-
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
22-
<script async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
21+
<script defer src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
22+
<script defer src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
2323
{% endif %}
2424

2525
{% if jekyll.environment == 'production' %}

_includes/mermaid.html

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,27 @@
33
-->
44
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
55
<script>
6+
$(function() {
7+
let initTheme = "default";
68

7-
let initTheme = "default";
9+
if ($("html[mode=dark]").length > 0
10+
|| ($("html[mode]").length == 0
11+
&& window.matchMedia("(prefers-color-scheme: dark)").matches ) ) {
12+
initTheme = "dark";
13+
}
814

9-
if ($("html[mode=dark]").length > 0
10-
|| ($("html[mode]").length == 0
11-
&& window.matchMedia("(prefers-color-scheme: dark)").matches ) ) {
12-
initTheme = "dark";
13-
}
15+
let mermaidConf = {
16+
theme: initTheme /* <default|dark|forest|neutral> */
17+
};
1418

15-
let mermaidConf = {
16-
theme: initTheme /* <default|dark|forest|neutral> */
17-
};
1819

19-
/* Markdown converts to HTML */
20-
$("pre").has("code.language-mermaid").each(function() {
21-
let svgCode = $(this).children().html();
22-
$(this).addClass("unloaded");
23-
$(this).after(`<div class=\"mermaid\">${svgCode}</div>`);
24-
});
25-
26-
mermaid.initialize(mermaidConf);
20+
/* Markdown converts to HTML */
21+
$("pre").has("code.language-mermaid").each(function() {
22+
let svgCode = $(this).children().html();
23+
$(this).addClass("unloaded");
24+
$(this).after(`<div class=\"mermaid\">${svgCode}</div>`);
25+
});
2726

27+
mermaid.initialize(mermaidConf);
28+
});
2829
</script>

assets/js/_commons/back-to-top.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
/*
22
Reference: https://bootsnipp.com/snippets/featured/link-to-top-page
33
*/
4-
$(window).scroll(function() {
5-
if ($(this).scrollTop() > 50
6-
&& $("#sidebar-trigger").css("display") === "none") {
7-
$("#back-to-top").fadeIn();
8-
} else {
9-
$("#back-to-top").fadeOut();
10-
}
11-
});
124

135
$(function() {
6+
$(window).scroll(function() {
7+
if ($(this).scrollTop() > 50 &&
8+
$("#sidebar-trigger").css("display") === "none") {
9+
$("#back-to-top").fadeIn();
10+
} else {
11+
$("#back-to-top").fadeOut();
12+
}
13+
});
14+
1415
$("#back-to-top").click(function() {
15-
$("body,html").animate({scrollTop: 0}, 800);
16+
$("body,html").animate({
17+
scrollTop: 0
18+
}, 800);
1619
return false;
1720
});
18-
});
21+
});

0 commit comments

Comments
 (0)