Skip to content

Commit 9c36be1

Browse files
Optimize Website Load Time (alshedivat#435)
* Place js files after body tag * Add Analytics to the end of script * Minor nits and fixes Co-authored-by: Maruan Al-Shedivat <alshedivat.maruan@gmail.com>
1 parent 6968945 commit 9c36be1

File tree

4 files changed

+30
-31
lines changed

4 files changed

+30
-31
lines changed

_includes/head.html

-30
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,3 @@
4242
{% endif %}
4343
<link rel="stylesheet" href="{{ '/assets/css/main.css' | relative_url }}">
4444
<link rel="canonical" href="{{ page.url | replace:'index.html','' | relative_url }}">
45-
46-
<!-- JQuery -->
47-
{% include scripts/jquery.html %}
48-
49-
<!-- Theming-->
50-
{% if site.enable_darkmode %}
51-
<script src="{{ '/assets/js/theme.js' | relative_url }}"></script>
52-
<script src="{{ '/assets/js/dark_mode.js' | relative_url }}"></script>
53-
{% endif %}
54-
55-
{% if site.enable_google_analytics %}
56-
<!-- Global site tag (gtag.js) - Google Analytics -->
57-
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
58-
<script>
59-
window.dataLayer = window.dataLayer || [];
60-
function gtag() { dataLayer.push(arguments); }
61-
gtag('js', new Date());
62-
63-
gtag('config', '{{ site.google_analytics }}');
64-
</script>
65-
{% endif %}
66-
67-
{% if site.enable_panelbear_analytics %}
68-
<!-- Panelbear Analytics - We respect your privacy -->
69-
<script async src="https://cdn.panelbear.com/analytics.js?site={{site.panelbear_analytics}}"></script>
70-
<script>
71-
window.panelbear = window.panelbear || function() { (window.panelbear.q = window.panelbear.q || []).push(arguments); };
72-
panelbear('config', { site: '{{site.panelbear_analytics}}' });
73-
</script>
74-
{% endif %}

_includes/scripts/analytics.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{% if site.enable_google_analytics %}
2+
<!-- Global site tag (gtag.js) - Google Analytics -->
3+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
4+
<script>
5+
window.dataLayer = window.dataLayer || [];
6+
function gtag() { dataLayer.push(arguments); }
7+
gtag('js', new Date());
8+
9+
gtag('config', '{{ site.google_analytics }}');
10+
</script>
11+
{% endif %}
12+
13+
14+
{% if site.enable_panelbear_analytics %}
15+
<!-- Panelbear Analytics - We respect your privacy -->
16+
<script async src="https://cdn.panelbear.com/analytics.js?site={{site.panelbear_analytics}}"></script>
17+
<script>
18+
window.panelbear = window.panelbear || function() { (window.panelbear.q = window.panelbear.q || []).push(arguments); };
19+
panelbear('config', { site: '{{site.panelbear_analytics}}' });
20+
</script>
21+
{% endif %}

_includes/scripts/misc.html

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
{% if site.enable_darkmode %}
2+
<!-- Dark Mode -->
3+
<script src="{{ '/assets/js/theme.js' | relative_url }}"></script>
4+
<script src="{{ '/assets/js/dark_mode.js' | relative_url }}"></script>
5+
{% endif %}
6+
17
{% if site.enable_tooltips %}
28
<!-- Enable Tooltips -->
39
<script type="text/javascript">

_layouts/default.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<head>
55
{% if page.redirect %}<meta http-equiv="refresh" content="3; url={{ site.baseurl | prepend: site.url }}/" />{% endif %}
66
{% include head.html %}
7-
{% include scripts/mathjax.html %}
87
</head>
98

109
<body class="{% if site.navbar_fixed %}fixed-top-nav{% endif %} {% unless site.footer_fixed %}sticky-bottom-footer{% endunless %}">
@@ -25,8 +24,11 @@
2524

2625
</body>
2726

27+
{% include scripts/jquery.html %}
2828
{% include scripts/bootstrap.html %}
2929
{% include scripts/mansory.html %}
3030
{% include scripts/misc.html %}
31+
{% include scripts/mathjax.html %}
32+
{% include scripts/analytics.html %}
3133

3234
</html>

0 commit comments

Comments
 (0)