Skip to content

Commit

Permalink
Preload template
Browse files Browse the repository at this point in the history
  • Loading branch information
infloent committed Oct 18, 2024
1 parent d6e6d19 commit 397e770
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions head.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,28 @@
<script>
/* Preload header */
const headerMeta = document.querySelector('meta[name="header"]');
const url = headerMeta?.content.trim();
if (url?.toLowerCase() !== 'false') {
const headerUrl = headerMeta?.content.trim();
if (headerUrl?.toLowerCase() !== 'false') {
const link = document.createElement('link');
link.setAttribute('rel', 'preload');
link.setAttribute('as', 'fetch');
link.setAttribute('crossorigin', 'anonymous');
link.href = url ? `${url}.plain.html` : '/header.plain.html';
link.href = headerUrl ? `${headerUrl}.plain.html` : '/header.plain.html';
document.head.appendChild(link);
}

/* Preload template */
const templateMeta = document.querySelector('meta[name="template"]');
const tplUrl = templateMeta?.content.trim();
if (typeof tplUrl !== 'undefined') {
if (!tplUrl.includes('/')) {
tplUrl = '/templates/'.concat(tplUrl);
}
const link = document.createElement('link');
link.setAttribute('rel', 'preload');
link.setAttribute('as', 'fetch');
link.setAttribute('crossorigin', 'anonymous');
link.href = `${tplUrl}.plain.html`;
document.head.appendChild(link);
}
</script>
Expand All @@ -19,6 +34,11 @@
}
</style>
<link rel="stylesheet" href="/styles/styles.css" />
<script src="/scripts/component-base.js" type="module"></script>
<script src="/scripts/libs.js" type="module"></script>
<script src="/scripts/render/dom.js" type="module"></script>
<script src="/scripts/render/dom-manipulations.js" type="module"></script>
<script src="/scripts/render/dom-reducers.js" type="module"></script>
<script src="/scripts/render/dom-utils.js" type="module"></script>
<script src="/scripts/component-list/component-list.js" type="module"></script>
<script src="/scripts/index.js" type="module"></script>
<script src="/scripts/component-base.js" type="module"></script>

0 comments on commit 397e770

Please sign in to comment.