Skip to content

Commit 36fb528

Browse files
committed
refactor(website): optimise video loading
1 parent 2cdf82a commit 36fb528

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

apps/website/index.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
1111
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&display=swap" rel="stylesheet" />
1212
<link rel="stylesheet" href="/src/style.css" />
13+
<link rel="preload" href="/videos/overview.mp4" as="video" type="video/mp4" />
1314
</head>
1415
<body>
1516
<!-- Hero + Product Viewer -->
@@ -71,14 +72,14 @@ <h1 class="hero-title">Codelegate</h1>
7172
<!-- Overview -->
7273
<div class="pv-tour active" data-tour-panel="overview">
7374
<div class="pv-tour-media">
74-
<video class="pv-video" autoplay muted playsinline src="/videos/overview.mp4"></video>
75+
<video class="pv-video" autoplay muted playsinline preload="auto" src="/videos/overview.mp4"></video>
7576
</div>
7677
</div>
7778

7879
<!-- Agent Support -->
7980
<div class="pv-tour" data-tour-panel="agents">
8081
<div class="pv-tour-media">
81-
<video class="pv-video" muted playsinline src="/videos/agents.mp4"></video>
82+
<video class="pv-video" muted playsinline preload="none" data-src="/videos/agents.mp4"></video>
8283
</div>
8384
<div class="pv-tour-text">
8485
<h2 class="pv-tour-headline">Supports Claude Code and Codex CLI</h2>
@@ -89,7 +90,7 @@ <h2 class="pv-tour-headline">Supports Claude Code and Codex CLI</h2>
8990
<!-- Git Worktree -->
9091
<div class="pv-tour" data-tour-panel="worktree">
9192
<div class="pv-tour-media">
92-
<video class="pv-video" muted playsinline src="/videos/gitworktree.mp4"></video>
93+
<video class="pv-video" muted playsinline preload="none" data-src="/videos/gitworktree.mp4"></video>
9394
</div>
9495
<div class="pv-tour-text">
9596
<h2 class="pv-tour-headline">Git Worktree Management</h2>
@@ -100,7 +101,7 @@ <h2 class="pv-tour-headline">Git Worktree Management</h2>
100101
<!-- Keyboard Navigation -->
101102
<div class="pv-tour" data-tour-panel="keyboard">
102103
<div class="pv-tour-media">
103-
<video class="pv-video" muted playsinline src="/videos/keyboard.mp4"></video>
104+
<video class="pv-video" muted playsinline preload="none" data-src="/videos/keyboard.mp4"></video>
104105
</div>
105106
<div class="pv-tour-text">
106107
<h2 class="pv-tour-headline">Full Keyboard Navigation</h2>
@@ -111,7 +112,7 @@ <h2 class="pv-tour-headline">Full Keyboard Navigation</h2>
111112
<!-- All TUI Tools -->
112113
<div class="pv-tour" data-tour-panel="tui">
113114
<div class="pv-tour-media">
114-
<video class="pv-video" muted playsinline src="/videos/cli.mp4"></video>
115+
<video class="pv-video" muted playsinline preload="none" data-src="/videos/cli.mp4"></video>
115116
</div>
116117
<div class="pv-tour-text">
117118
<h2 class="pv-tour-headline">Use Whatever All TUI Tools You Like</h2>

apps/website/src/main.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,36 @@ navItems.forEach((btn) => {
3030
}
3131
});
3232

33-
// Play video in panel, pause all others; restart from beginning
33+
// Play video in panel, pause all others; lazy-load src on first access
3434
function playVideoInPanel(panel) {
3535
panels.forEach((p) => {
3636
const v = p.querySelector("video");
3737
if (v) v.pause();
3838
});
3939
const video = panel.querySelector("video");
4040
if (video) {
41+
// Lazy-load: move data-src to src on first play
42+
if (!video.src && video.dataset.src) {
43+
video.src = video.dataset.src;
44+
}
4145
video.currentTime = 0;
4246
video.play();
4347
}
4448
}
4549

50+
// After overview finishes loading, prefetch the other videos in background
51+
const overviewVideo = panels.get("overview").querySelector("video");
52+
overviewVideo.addEventListener("canplaythrough", () => {
53+
panels.forEach((panel, key) => {
54+
if (key === "overview") return;
55+
const v = panel.querySelector("video");
56+
if (v && !v.src && v.dataset.src) {
57+
v.preload = "auto";
58+
v.src = v.dataset.src;
59+
}
60+
});
61+
}, { once: true });
62+
4663
// 2-second delay before looping: pause at end, then restart after 2s
4764
document.querySelectorAll(".pv-video").forEach((video) => {
4865
video.loop = false; // we handle looping manually
@@ -53,7 +70,7 @@ document.querySelectorAll(".pv-video").forEach((video) => {
5370
video.currentTime = 0;
5471
video.play();
5572
}
56-
}, 2000);
73+
}, 3000);
5774
});
5875
});
5976

0 commit comments

Comments
 (0)