🎥 Make videos programmatically with React
preloading page
Jonny Burger36b7cb49beb1
diff --git a/packages/docs/blog/2022-01-04-remotion-2-6.md b/packages/docs/blog/2022-01-04-remotion-2-6.mdindex 03b2c30bee..1ee55e4536 100644--- a/packages/docs/blog/2022-01-04-remotion-2-6.md+++ b/packages/docs/blog/2022-01-04-remotion-2-6.md@@ -23,7 +23,7 @@ You can dynamically update the props of the video at runtime, which creates an eOn mobile, restrictive policies prevent auto-play of audio content. [We help you](/docs/player/autoplay) architect your player so it can play audio in as many cases as possible while still respecting the browser policies. This includes the option to mount silent audio tags, activate them while the user interacts with the page and use them later to play audio.-In this release, we added a new [`renderLoading`](/docs/player/api#renderloading) prop and wrote docs for how to [scale your player](/docs/player/scaling), [code-sharing between Remotion and Create React App/Next.JS](/docs/player/integration) and preloading assets (TODO)+In this release, we added a new [`renderLoading`](/docs/player/api#renderloading) prop and wrote docs for how to [scale your player](/docs/player/scaling), [code-sharing between Remotion and Create React App/Next.JS](/docs/player/integration) and [preloading assets](/docs/player/preloading).[See the landing page for `@remotion/player`](/player)[Demo and Documentation](/docs/player)diff --git a/packages/docs/docs/player/preloading.md b/packages/docs/docs/player/preloading.mdnew file mode 100644index 0000000000..f4f9a7c9b3--- /dev/null+++ b/packages/docs/docs/player/preloading.md@@ -0,0 +1,43 @@+---+sidebar_label: "Preloading"+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++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";++ document.head.appendChild(link);+};++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}/>+```diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.jsindex 6bd23f9d12..ff0d180ee5 100644--- a/packages/docs/sidebars.js+++ b/packages/docs/sidebars.js@@ -11,6 +11,7 @@ module.exports = {"player/scaling","player/integration","player/autoplay",+ "player/preloading",],someSidebar: [{