Skip to content

🎥 Make videos programmatically with React

update player preloading documentation

Jonny Burgerd0125c726d9c
diff --git a/packages/docs/docs/player/preloading.md b/packages/docs/docs/player/preloading.md
index f4f9a7c9b3..e906a2dd4d 100644
--- a/packages/docs/docs/player/preloading.md
+++ b/packages/docs/docs/player/preloading.md
@@ -5,39 +5,15 @@ title: "Preloading assets"
By default, assets such as videos, audio, or images will only be loaded as they enter the video. You can preload those assets beforehand to make them play immediately once they enter the video.
-## Example: Preloading a video
+## Preloading videos using `@remotion/preload`
-Put this outside a component (or inside an `useEffect`):
+For videos, you can use the [`preloadVideo()`](/docs/preload/preload-video) API. Put this outside a component (or inside an `useEffect`):
-```tsx
-const preload = (video: string) => {
- const link = document.createElement("link");
- link.rel = "preload";
- link.href = video;
- link.as = "video";
+```tsx twoslash
+import { preloadVideo } from "@remotion/preload";
- document.head.appendChild(link);
-};
+const unpreload = preloadVideo("https://example.com/video.mp4");
-preload("https://example.com/video.mp4");
-```
-
-## Preloading URLs that redirect
-
-If your URL redirects (such as the Vimeo URL in the example), you need to resolve it to the real URL first:
-
-```tsx
-const resolveRedirect = async (video: string) => {
- const res = await fetch(video);
- return res.url;
-};
-
-const realUrl = await resolveRedirect(
- "https://player.vimeo.com/external/291648067.hd.mp4?s=94998971682c6a3267e4cbd19d16a7b6c720f345&profile_id=175&oauth2_token_id=57447761"
-);
-
-preload(realUrl)
-
-// Make sure you use the resolved URL
-<Video src={realUrl}/>
+// Later, you can optionally clean up the preload
+unpreload();
```