Skip to content

Commit 559dcf9

Browse files
committed
feat(index): preload LCP (current day picture 1) with manual JS
1 parent 6f41c60 commit 559dcf9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

index.html

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,41 @@
2525
<div id="app"></div>
2626
<script type="module" src="/src/main.ts"></script>
2727
<script async defer src="https://cabin.archiguesser.com/hello.js"></script>
28+
<script>
29+
const urlParameters = new URLSearchParams(window.location.search);
30+
const requestedDay = urlParameters.get("day");
31+
const isArcadeMode = urlParameters.get("challenge") || false;
32+
33+
if (!isArcadeMode) {
34+
try {
35+
let day;
36+
if (
37+
requestedDay &&
38+
!isNaN(parseInt(requestedDay))
39+
) {
40+
day = parseInt(requestedDay);
41+
} else {
42+
const StartDate = Date.UTC(2022,6,1);
43+
const now = new Date();
44+
const timestamp1 = Date.UTC(
45+
now.getFullYear(),
46+
now.getMonth(),
47+
now.getDate(),
48+
);
49+
const differenceInMilliseconds = timestamp1 - StartDate;
50+
const differenceInDays = differenceInMilliseconds / 1000 / 60 / 60 / 24;
51+
52+
day = differenceInDays;
53+
}
54+
55+
let link = document.createElement('link');
56+
link.as = 'image';
57+
link.type = 'image/jpeg';
58+
link.rel = 'preload';
59+
link.href = `${day}/1.jpg`;
60+
document.head.appendChild(link);
61+
} catch (e) { console.error(e); }
62+
}
63+
</script>
2864
</body>
2965
</html>

0 commit comments

Comments
 (0)