Skip to content

Commit

Permalink
move layout scripts to the end of the body
Browse files Browse the repository at this point in the history
  • Loading branch information
vintikzzz committed Dec 4, 2024
1 parent 9350368 commit ac81630
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 36 deletions.
52 changes: 21 additions & 31 deletions assets/src/js/app/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,25 @@ import {bindAsync} from '../lib/async';
import initAsyncView from '../lib/asyncView';

const initTheme = (await import('../lib/themeSelector')).initTheme;
window.loaded = false;
function onLoad() {
if (window.loaded) return;
window.loaded = true;
initTheme(document.querySelector('[data-toggle-theme]'));
document.body.style.display = 'flex';
hideProgress();
bindAsync({
async fetch(f, url, fetchParams) {
showProgress();
fetchParams.headers['X-CSRF-TOKEN'] = window._CSRF;
fetchParams.headers['X-SESSION-ID'] = window._sessionID;
const res = await fetch(url, fetchParams);
hideProgress();
return res;
},
update(key, val) {
if (key === 'title') document.querySelector('title').innerText = val;
},
fallback: {
selector: 'main',
layout: 'async',
},
});
initAsyncView();
}

if (document.readyState === 'complete') {
onLoad();
} else {
document.addEventListener('readystatechange', onLoad, true);
}
initTheme(document.querySelector('[data-toggle-theme]'));
document.body.style.display = 'flex';
hideProgress();
bindAsync({
async fetch(f, url, fetchParams) {
showProgress();
fetchParams.headers['X-CSRF-TOKEN'] = window._CSRF;
fetchParams.headers['X-SESSION-ID'] = window._sessionID;
const res = await fetch(url, fetchParams);
hideProgress();
return res;
},
update(key, val) {
if (key === 'title') document.querySelector('title').innerText = val;
},
fallback: {
selector: 'main',
layout: 'async',
},
});
initAsyncView();
12 changes: 7 additions & 5 deletions templates/layouts/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
{{- if useUmami }}
window._umami = {{ umamiConfig | json }};
{{- end }}
{{- if useAuth }}
window._sessionExpired = {{ .User.Expired }};
{{- end }}
</script>
{{ "layout.js" | asset }}
{{ "baskerville.css" | asset }}
{{ "style.css" | asset }}
{{- if useAuth }}
<script>window._sessionExpired = {{ .User.Expired }};</script>
{{ "auth.js" | asset }}
{{- end }}
{{- template "head_extra" . }}
</head>
<body class="flex flex-col min-h-screen">
Expand All @@ -47,5 +45,9 @@
</div>
</div>
</div>
{{ "layout.js" | asset }}
{{- if useAuth }}
{{ "auth.js" | asset }}
{{- end }}
</body>
</html>

0 comments on commit ac81630

Please sign in to comment.