Skip to content

Commit

Permalink
Optimize Website Load Time (#435)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
pourmand1376 and alshedivat authored Oct 30, 2021
1 parent 6968945 commit 9c36be1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
30 changes: 0 additions & 30 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,3 @@
{% endif %}
<link rel="stylesheet" href="{{ '/assets/css/main.css' | relative_url }}">
<link rel="canonical" href="{{ page.url | replace:'index.html','' | relative_url }}">

<!-- JQuery -->
{% include scripts/jquery.html %}

<!-- Theming-->
{% if site.enable_darkmode %}
<script src="{{ '/assets/js/theme.js' | relative_url }}"></script>
<script src="{{ '/assets/js/dark_mode.js' | relative_url }}"></script>
{% endif %}

{% if site.enable_google_analytics %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());

gtag('config', '{{ site.google_analytics }}');
</script>
{% endif %}

{% if site.enable_panelbear_analytics %}
<!-- Panelbear Analytics - We respect your privacy -->
<script async src="https://cdn.panelbear.com/analytics.js?site={{site.panelbear_analytics}}"></script>
<script>
window.panelbear = window.panelbear || function() { (window.panelbear.q = window.panelbear.q || []).push(arguments); };
panelbear('config', { site: '{{site.panelbear_analytics}}' });
</script>
{% endif %}
21 changes: 21 additions & 0 deletions _includes/scripts/analytics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% if site.enable_google_analytics %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());

gtag('config', '{{ site.google_analytics }}');
</script>
{% endif %}


{% if site.enable_panelbear_analytics %}
<!-- Panelbear Analytics - We respect your privacy -->
<script async src="https://cdn.panelbear.com/analytics.js?site={{site.panelbear_analytics}}"></script>
<script>
window.panelbear = window.panelbear || function() { (window.panelbear.q = window.panelbear.q || []).push(arguments); };
panelbear('config', { site: '{{site.panelbear_analytics}}' });
</script>
{% endif %}
6 changes: 6 additions & 0 deletions _includes/scripts/misc.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{% if site.enable_darkmode %}
<!-- Dark Mode -->
<script src="{{ '/assets/js/theme.js' | relative_url }}"></script>
<script src="{{ '/assets/js/dark_mode.js' | relative_url }}"></script>
{% endif %}

{% if site.enable_tooltips %}
<!-- Enable Tooltips -->
<script type="text/javascript">
Expand Down
4 changes: 3 additions & 1 deletion _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<head>
{% if page.redirect %}<meta http-equiv="refresh" content="3; url={{ site.baseurl | prepend: site.url }}/" />{% endif %}
{% include head.html %}
{% include scripts/mathjax.html %}
</head>

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

</body>

{% include scripts/jquery.html %}
{% include scripts/bootstrap.html %}
{% include scripts/mansory.html %}
{% include scripts/misc.html %}
{% include scripts/mathjax.html %}
{% include scripts/analytics.html %}

</html>

0 comments on commit 9c36be1

Please sign in to comment.