What are the best practices for hosting videos on Vercel?

Learn the ideal solutions for using video files like .mp4 and .gif on Vercel to prevent excess bandwidth consumption.
Last updated on December 22, 2023
Edge Network & CachingLimits, Usage and PricingFrameworks

When building your site on Vercel, you might want to add video assets. Videos can be an important part of your design or content marketing. However, large video files can often lead to excessive bandwidth usage.

For example, you might want a background image as the header on your marketing site.

<video width="320" height="240" loop autoPlay>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
An example auto-playing Video HTML element.

You can store files with Vercel Blob, a frontend-friendly solution for storing files in the cloud.

app/api/upload/route.ts
import { put } from '@vercel/blob';
export async function POST(request: Request) {
const { searchParams } = new URL(request.url);
const filename = searchParams.get('filename');
const blob = await put(filename, request.body, {
access: 'public',
});
return Response.json(blob);
}
Vercel Blob enables you to programmatically upload video files.

You can also host video assets (like .mp4 and .gif files) on dedicated content platforms such as:

Third-party solutions may offer additional options to customize, compress, and transform your video files. It's important to ensure your videos are compressed and optimized regardless of the platform they're being hosted on.

Vercel has built-in Image Optimization, which works with zero-configuration using the Next.js Image Component. We recommend using these solutions for optimal Core Web Vitals and performance.

For example, here's a background image using next/image (Demo):

import Image from 'next/image'
import ViewSource from '../components/view-source'
import { bgWrap, bgText } from '../styles.module.css'
const Background = () => (
<div>
<ViewSource pathname="pages/background.js" />
<div className={bgWrap}>
<Image
alt="Mountains"
src="/mountains.jpg"
layout="fill"
objectFit="cover"
quality={100}
/>
</div>
<p className={bgText}>
Image Component
<br />
as a Background
</p>
</div>
)
export default Background
An example background image using the Next.js Image component.

Couldn't find the guide you need?