From 88054afa22136c6bce44e7b46beb801dcec0840d Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Mon, 24 Aug 2020 02:08:30 +0200 Subject: [PATCH] Add a early js script. --- assets/js/script-early.js | 13 +++++++++++++ assets/js/script.js | 3 +-- layouts/partials/scripts.html | 2 ++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 assets/js/script-early.js diff --git a/assets/js/script-early.js b/assets/js/script-early.js new file mode 100644 index 0000000..7b671f7 --- /dev/null +++ b/assets/js/script-early.js @@ -0,0 +1,13 @@ +/** + * @file + * A JavaScript file for the theme. Runs first, before jQuery etc. have loaded. + */ + +(function () { + + 'use strict'; + + // Add a js class to the html-tag when JavsScript is active. + document.querySelector('html').classList.replace('nojs', 'js'); + +})(); diff --git a/assets/js/script.js b/assets/js/script.js index 8f8fecc..7cfe99d 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -7,7 +7,6 @@ 'use strict'; - // Add a js class to the html-tag when JavsScript is active. - $('html').removeClass('nojs').addClass('js'); + // Place your code here. })(u); diff --git a/layouts/partials/scripts.html b/layouts/partials/scripts.html index 6e6c01e..33fbe19 100644 --- a/layouts/partials/scripts.html +++ b/layouts/partials/scripts.html @@ -1,3 +1,5 @@ +{{ $early := resources.Get "js/script-early.js" | minify | fingerprint -}} + {{ if $.Param "jquery" -}} {{ $jquery := resources.Get "js/lib/jquery.slim.min.js" | fingerprint -}}