Skip to main content

preloadVideo()

This function is part of the @remotion/preload package.

This function preloads a video in the DOM so that when an HTML5 <video> element is mounted, it can play immediately.

It only affects HTML5 video elements such as <Html5Video>, not <Video> from @remotion/media.

warning

Using preloadVideo() is not recommended. Use premounting instead to give media time to load and initialize before it appears in the Player or Studio.

Usage​

import {preloadVideo} from '@remotion/preload';

const unpreload = preloadVideo('https://remotion.media/BigBuckBunny.mp4');

// If you want to un-preload the video later
unpreload();

How it works​

  • On Firefox, it appends a <link rel="preload" as="video"> tag in the head element of the document.
  • In other browsers, it appends a <video preload="auto"> tag in the body element of the document. On iOS Safari, preload="metadata" is used instead.

Handle redirects​

preloadVideo() resolves redirects automatically. It first fetches the URL to determine the final URL after any redirects, and then preloads the final URL.

This requires the resource to support CORS. If the URL cannot be fetched, for example because the resource does not support CORS or the request times out, nothing gets preloaded and the error is logged to the console.

To obtain the final URL yourself, use resolveRedirect().

Compatibility​

BrowsersEnvironments
Chrome
Firefox
Safari

This function preloads HTML5 video elements. It does not preload the assets used by @remotion/media for client-side rendering.

See also​