Skip to content

Commit 19b6831

Browse files
committed
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.
1 parent a156649 commit 19b6831

File tree

4 files changed

+5
-17
lines changed

4 files changed

+5
-17
lines changed

‎assets/js/body-start.js‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

‎assets/js/head-early.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { scrollToActive } from 'js/helpers/index';
2+
import { initColorScheme } from './alpinejs/stores/index';
23

34
(function () {
5+
// This allows us to initialize the color scheme before AlpineJS etc. is loaded.
6+
initColorScheme();
7+
48
// Now we know that the browser has JS enabled.
59
document.documentElement.classList.remove('no-js');
610

‎assets/js/main.js‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ import focus from '@alpinejs/focus';
88

99
var debug = 0 ? console.log.bind(console, '[index]') : function () {};
1010

11-
// Turbolinks init.
12-
(function () {
13-
document.addEventListener('turbo:render', function (e) {
14-
// This is also called right after the body start. This is added to prevent flicker on navigation.
15-
initColorScheme();
16-
});
17-
})();
18-
1911
// Set up and start Alpine.
2012
(function () {
2113
// Register AlpineJS plugins.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{{ with resources.Get "js/body-start.js" | js.Build (dict "minify" true) }}
2-
{{ partial "helpers/linkjs.html" (dict "r" . "attributes" (dict "" "")) }}
3-
{{ end }}
1+
{{ partial "helpers/linkjs.html" (dict "r" . "attributes" (dict "" "")) }}

0 commit comments

Comments
 (0)