From 98e9ef5f0c2d70130d5271385d400578435f5ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Wed, 17 Sep 2025 16:02:32 +0200 Subject: [PATCH] theme: Move initColorScheme() to head This should reduce the amount of blocking JS. Also remove the initColorScheme() in `turbo:render` which is not needed after we moved the `dark` class from body to documentElement. --- assets/js/body-start.js | 6 ------ assets/js/head-early.js | 4 ++++ assets/js/main.js | 8 -------- layouts/_partials/layouts/hooks/body-start.html | 3 --- 4 files changed, 4 insertions(+), 17 deletions(-) delete mode 100644 assets/js/body-start.js diff --git a/assets/js/body-start.js b/assets/js/body-start.js deleted file mode 100644 index f9b596671..000000000 --- a/assets/js/body-start.js +++ /dev/null @@ -1,6 +0,0 @@ -import { initColorScheme } from './alpinejs/stores/index'; - -(function () { - // This allows us to initialize the color scheme before AlpineJS etc. is loaded. - initColorScheme(); -})(); diff --git a/assets/js/head-early.js b/assets/js/head-early.js index 250bdd6cb..b21eb58a2 100644 --- a/assets/js/head-early.js +++ b/assets/js/head-early.js @@ -1,6 +1,10 @@ import { scrollToActive } from 'js/helpers/index'; +import { initColorScheme } from './alpinejs/stores/index'; (function () { + // This allows us to initialize the color scheme before AlpineJS etc. is loaded. + initColorScheme(); + // Now we know that the browser has JS enabled. document.documentElement.classList.remove('no-js'); diff --git a/assets/js/main.js b/assets/js/main.js index 14440044b..c12be19fa 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -8,14 +8,6 @@ import focus from '@alpinejs/focus'; var debug = 0 ? console.log.bind(console, '[index]') : function () {}; -// Turbolinks init. -(function () { - document.addEventListener('turbo:render', function (e) { - // This is also called right after the body start. This is added to prevent flicker on navigation. - initColorScheme(); - }); -})(); - // Set up and start Alpine. (function () { // Register AlpineJS plugins. diff --git a/layouts/_partials/layouts/hooks/body-start.html b/layouts/_partials/layouts/hooks/body-start.html index 3430bd846..e69de29bb 100644 --- a/layouts/_partials/layouts/hooks/body-start.html +++ b/layouts/_partials/layouts/hooks/body-start.html @@ -1,3 +0,0 @@ -{{ with resources.Get "js/body-start.js" | js.Build (dict "minify" true) }} - {{ partial "helpers/linkjs.html" (dict "r" . "attributes" (dict "" "")) }} -{{ end }}