Skip to content

πŸŽ₯ Make videos programmatically with React

write docs

Jonny Burger555966d11d78
diff --git a/packages/docs/docs/importing-assets.md b/packages/docs/docs/importing-assets.md
index be22e16068..473f41aaab 100644
--- a/packages/docs/docs/importing-assets.md
+++ b/packages/docs/docs/importing-assets.md
@@ -88,4 +88,4 @@ See the [dedicated page about fonts](/docs/fonts).
## Importing arbitrary files
-Create a `/public` folder in your project and use the [`staticFile()`](/docs/staticfile) API to get a URL reference of the asset that you can load into your project.
+Create a `public/` folder in your project and use the [`staticFile()`](/docs/staticfile) API to get a URL reference of the asset that you can load into your project.
diff --git a/packages/docs/docs/staticfile.md b/packages/docs/docs/staticfile.md
index 4e01ba52d2..6f55660e1c 100644
--- a/packages/docs/docs/staticfile.md
+++ b/packages/docs/docs/staticfile.md
@@ -3,4 +3,60 @@ id: staticfile
title: staticFile()
---
-TODO
+_Available from v2.5.6._
+
+Turns a file in your `public/` folder into an URL which you can then load into your project.
+
+```tsx twoslash
+import { Img, staticFile } from "remotion";
+
+const myImage = staticFile(`/my-image.png`);
+
+// ...
+
+<Img src={myImage} />;
+```
+
+## Example
+
+Start by creating a `public/` folder in the root of your video project:
+
+```txt
+my-video/
+β”œβ”€ node_modules/
+β”œβ”€ public/
+β”‚ β”œβ”€ my-image.png
+β”‚ β”œβ”€ font.woff2
+β”œβ”€ src/
+β”‚ β”œβ”€ Video.tsx
+β”‚ β”œβ”€ index.tsx
+β”œβ”€ package.json
+```
+
+Get an URL reference of your asset:
+
+```tsx twoslash
+import { staticFile } from "remotion";
+
+const myImage = staticFile(`/my-image.png`); // "/static-32e8nd/my-image.png"
+const font = staticFile(`/font.woff2`); // "/static-32e8nd/font.woff2"
+```
+
+You can now load the asset via:
+
+- [`<Img />`](/docs/img), [`<Audio/>`](/docs/audio), [`<Video/>`](/docs/video) tag
+- Fetch API
+- [FontFace()](/docs/fonts)
+- Any other loader that supports data fetching via URL
+
+## Why can't I just pass a string?
+
+If you are a Create React App or Next.JS user, you might be used to just to be able to reference the asset from a string: `<img src="/my-image.png"/>`. Remotion is different in that you need to use the `staticFile()` API because:
+
+- It prevents breaking when deploying your site into a subdirectory of a domain: `https://example.com/my-folder/my-logo.png`
+- It avoids conflicts with composition names which might share the same name (for example `http://localhost:3000/conflicting-name` while running the preview)
+- It allows us to make paths framework-agnostic, so your code can work across Remotion, Create React App, Next.JS and potentially other frameworks.
+
+## See also
+
+- [Loading assets](/docs/assets)
diff --git a/packages/docs/docs/using-fonts.md b/packages/docs/docs/using-fonts.md
index e6e9454d2a..f40cf3b3bb 100644
--- a/packages/docs/docs/using-fonts.md
+++ b/packages/docs/docs/using-fonts.md
@@ -23,7 +23,7 @@ const MyComp: React.FC = () => {
## Example using local fonts
-Put the font into your `/public` folder and use the [`staticFile()`](/docs/staticfile) API to load the font. Use the `FontFace` browser API to load the font. [Click here](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face) to read the syntax that can be used for the Font Face API.
+Put the font into your `public/` folder and use the [`staticFile()`](/docs/staticfile) API to load the font. Use the `FontFace` browser API to load the font. [Click here](https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face) to read the syntax that can be used for the Font Face API.
Put this somewhere in your app where it gets executed: