i have my portfolio but my web performance is not good beacause of video so what video…
- User
i have my portfolio but my web performance is not good beacause of video so what video format i use webm to mp4 next js app
- Assistant
i have my portfolio but my web performance is not good beacause of video so what video format i use webm to mp4 next js app
Improving web performance, especially when dealing with videos, is crucial for providing a good user experience. When choosing the video format, WebM and MP4 are the most common ones used on the web.
Here's a brief comparison and some tips on using these formats efficiently in your Next.js app:
Use Both Formats:
Optimize Video Files:
Use Lazy Loading:
loading="lazy" attribute can be used for images, but for videos, you might need a bit of JavaScript.Implement Caching and CDN:
Here’s an example of how you can implement this in your Next.js app:
import { useEffect, useState } from 'react';
const VideoComponent = () => {
const [videoSrc, setVideoSrc] = useState('');
useEffect(() => {
if (window.navigator.connection.effectiveType === '4g' || window.navigator.connection.effectiveType === '5g') {
// Load higher quality video for fast network connections
setVideoSrc('/path/to/high-quality-video.webm');
} else {
// Load lower quality video for slower network connections
setVideoSrc('/path/to/low-quality-video.mp4');
}
}, []);
return (
<video controls preload="auto">
<source src={videoSrc} type="video/webm" />
<source src={videoSrc} type="video/mp4" />
Your browser does not support the video tag.
</video>
);
};
export default VideoComponent;
<link rel="preload" href="/path/to/video.webm" as="video" /> in your _document.js to preload important video files.For converting videos to WebM and MP4, you can use FFmpeg:
# Convert to WebM
ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 0 -crf 30 output.webm
# Convert to MP4
ffmpeg -i input.webm -vcodec h264 -acodec aac output.mp4
By following these guidelines, you should see a noticeable improvement in your portfolio's web performance despite using videos.
Not yet included in a published release.