react-media-optimizer
v1.1.1
Published
Drop-in React component for auto-optimized images & media with lazy loading, WebP conversion, SEO metadata, and performance optimization
Maintainers
Readme
🚀 React Media Optimizer
Drop-in image & video optimization for React applications. Automatically compress, lazy-load, convert media, AND inject SEO metadata to improve performance, UX, and search rankings with minimal effort.
📊 Average improvements: 60% faster LCP, 75% smaller images, 40% better SEO scores, +25% Google Image CTR Results vary depending on implementation and infrastructure.
✨ Why Choose React Media Optimizer?
| Feature | Benefit | Impact | |---------|---------|--------| | Auto Lazy Loading | Images/videos load only when visible | ⬇️ 50-80% initial page weight | | Auto Blur Placeholders | Smooth fade-in from blurred preview to sharp image | ⬆️ Better perceived load speed & premium UX | | WebP/WebM Conversion | Modern formats with better compression | ⬇️ 25-35% smaller file sizes | | Client-side Compression | Reduce upload sizes before server | ⬇️ 60-80% upload bandwidth | | SSR/SSG Safe | Works with Next.js, Gatsby, Remix | ✅ Zero hydration errors | | Zero Configuration | Sensible defaults out of the box | ⏱️ 5-minute integration | | SEO Features | Automatic JSON-LD schema injection | ⬆️ +25% Google Image CTR |
🎯 v1.1.0: The SEO Update
🔔 New SEO Features for Images:
- Google "Licensable" Badge - Automatically adds license metadata
- ImageObject Schema - Rich snippets in Google Search
- E-E-AT Signals - Author, credit, copyright information
- representativeOfPage - Marks hero images as page representatives
- Preload Priority - Automatic preload for LCP optimization
🎬 New SEO Features for Videos:
- Key Moments (Video Chapters) - Google shows clickable chapters in search
- VideoObject Schema - Duration, upload date, thumbnail in search results
- Transcript Support - Better accessibility and SEO
- Automatic Preload - Priority loading for critical videos
📦 Installation
Install using your preferred package manager.
npm
npm install react-media-optimizeryarn
yarn add react-media-optimizerpnpm
pnpm add react-media-optimizer📌 Peer Dependencies
This package requires React 16.8+ (Hooks support).
{
"react": ">=16.8.0",
"react-dom": ">=16.8.0"
}
🚀 Quick Start
1. Optimized Image with SEO
import { OptimizedImage } from 'react-media-optimizer';
function HeroSection() {
return (
<OptimizedImage
src="https://example.com/hero-banner.jpg"
alt="Product showcase"
width={1920}
height={1080}
// Performance props
placeholder="blur"
blurIntensity={25}
lazy={true}
webp={true}
quality={85}
priority="hero" // Preloads + representativeOfPage
className="rounded-lg shadow-xl"
// SEO props
license="CC BY-SA 4.0" // Google "Licensable" badge
author="John Doe Photography" // E-E-AT signal
credit="Shot on Sony A7III" // Photographer credit
caption="Sunset over mountains with beautiful colors" // Image description
keywords={["nature", "sunset", "mountains", "landscape"]}
contentLocation="Swiss Alps, Switzerland"
copyrightHolder="Nature Photography Inc"
datePublished="2024-01-15"
/>
);
}
**2. Optimized Video with Key Moments **
import { OptimizedVideo } from 'react-media-optimizer';
function TutorialVideo() {
// Define chapters for Key Moments
const chapters = [
{ startTime: 0, title: "Introduction" },
{ startTime: 300, title: "Installation" },
{ startTime: 900, title: "Components" },
{ startTime: 1800, title: "Hooks Deep Dive" },
{ startTime: 2700, title: "Conclusion" }
];
return (
<OptimizedVideo
src="https://example.com/tutorial.mp4"
poster="/thumbnail.jpg"
width="100%"
height="auto"
// Performance props
lazy={true}
webm={true}
mp4={true}
controls
priority="critical"
// Video SEO with Key Moments
title="Complete React Tutorial 2024"
description="Learn React from scratch in 1 hour - Hooks, Components, State Management"
author="React Academy"
license="Royalty Free"
duration={3600} // 1 hour in seconds
uploadDate="2024-01-15"
isFamilyFriendly={true}
keywords={["react", "tutorial", "javascript", "frontend", "web development"]}
transcript="Full video transcript available for accessibility and SEO..."
chapters={chapters} // Google Key Moments!
showChapters={true} // Show clickable chapters overlay
/>
);
}
** 3. Manual Schema Injection Example **
import {
generateImageSchema,
generateVideoSchema,
injectJsonLd
} from 'react-media-optimizer';
// Manual image schema injection
const imageSchema = generateImageSchema({
url: "https://example.com/image.jpg",
alt: "Beautiful landscape",
license: "CC BY-SA 4.0",
author: "John Doe",
caption: "Mountain landscape at sunset",
keywords: ["mountains", "sunset", "nature"],
isRepresentative: true
});
injectJsonLd(imageSchema);
// Manual video schema with chapters
const videoSchema = generateVideoSchema({
url: "https://example.com/video.mp4",
name: "Tutorial Video",
description: "Complete guide",
duration: 600,
uploadDate: "2024-01-15",
chapters: [
{ startTime: 0, title: "Intro" },
{ startTime: 120, title: "Main Content" }
]
});
injectJsonLd(videoSchema);
** 4. Priority Preload Example **
import { preloadCritical } from 'react-media-optimizer';
// Preload critical images/videos on page load
useEffect(() => {
preloadCritical([
{ src: '/hero.jpg', type: 'image' },
{ src: '/intro.mp4', type: 'video' },
{ src: '/logo.png', type: 'image' }
]);
}, []);## 📖 API Reference v1.1.0
<OptimizedImage /> Props
Basic Props
Performance Props
🔔 NEW SEO Props (v1.1.0)
Basic Props
Performance Props
🔔 NEW Video SEO Props (v1.1.0)
VideoChapter Interface
interface VideoChapter {
startTime: number; // seconds
title: string;
thumbnail?: string; // optional chapter thumbnail
}📊 Google Search Results Examples
Image with License Badge
Google Image Search will show:
🖼️ [Your Image]
📌 Licensable · CC BY-SA 4.0
👤 Author: John Doe Photography
📅 Published: Jan 15, 2024Video with Key Moments
Google Search will show:
🎬 Complete React Tutorial
⏱️ 1 hour · 50K views · Jan 15, 2024
Key Moments:
▸ 0:00 Introduction
▸ 5:00 Installation
▸ 15:00 Components
▸ 30:00 Hooks Deep Dive
▸ 45:00 Conclusion🛠️ Advanced Usage
Batch Preloading Critical Resources
import { preloadCritical } from 'react-media-optimizer';
// Preload all hero images and videos
useEffect(() => {
preloadCritical([
{ src: '/hero.jpg', type: 'image' },
{ src: '/intro.mp4', type: 'video' }
]);
}, []);
Generate Schema Manually
import { generateImageSchema, injectJsonLd } from 'react-media-optimizer';
const schema = generateImageSchema({
url: 'https://example.com/image.jpg',
alt: 'Beautiful landscape',
license: 'CC BY-SA 4.0',
author: 'John Doe'
});
injectJsonLd(schema);📈 Performance Impact
🏗️ Framework Integration
Next.js with SEO
import { OptimizedImage } from 'react-media-optimizer';
export default function HomePage() {
return (
<OptimizedImage
src="/hero.jpg"
alt="Homepage hero"
width={1200}
height={630}
priority="hero"
license="Commercial"
author="Company Name"
datePublished="2024-01-15"
/>
);
}Gatsby with Video SEO
import { OptimizedVideo } from 'react-media-optimizer';
const VideoPage = () => (
<OptimizedVideo
src={data.file.publicURL}
poster={data.thumbnail.publicURL}
title="Product Demo"
description="Watch our product in action"
chapters={[
{ startTime: 0, title: "Intro" },
{ startTime: 30, title: "Features" }
]}
duration={120}
uploadDate="2024-01-15"
/>
);🔄 Migration Guide
From v1.0.x to v1.1.0
<OptimizedImage
src="/image.jpg"
alt="Example"
// Old props still work
placeholder="blur"
lazy={true}
+ // NEW SEO props (optional)
+ license="CC BY-SA 4.0"
+ author="John Doe"
+ caption="Example image"
/>
<OptimizedVideo
src="/video.mp4"
poster="/poster.jpg"
+ // NEW video SEO props
+ title="Tutorial"
+ description="Learn how to use it"
+ chapters={[{ startTime: 0, title: "Start" }]}
+ duration={300}
+ uploadDate="2024-01-15"
/>📝 License Types Supported
// All supported licenses:
type LicenseType =
| 'CC0' // Public Domain
| 'CC BY' // Attribution
| 'CC BY-SA' // ShareAlike
| 'CC BY-NC' // NonCommercial
| 'CC BY-ND' // NoDerivatives
| 'CC BY-NC-SA' // NonCommercial-ShareAlike
| 'CC BY-NC-ND' // NonCommercial-NoDerivs
| 'Royalty Free' // Royalty-free
| 'Commercial' // Commercial use
| 'Public Domain' // Public domain
| 'All Rights Reserved' // All rights reserved
| 'MIT' // MIT License
| 'Apache 2.0'; // Apache 2.0📦 Changelog
v1.1.0 (Latest) 🎉
✨ SEO Features: Automatic JSON-LD schema injection
🏷️ License Badges: Google "Licensable" image support
🎬 Video Key Moments: Google video chapters
⚡ Priority Preload:
heroandcriticalpriority levels📝 E-E-AT Signals: Author, credit, copyright metadata
🎯 Rich Snippets: Better search result appearance
🔧 TypeScript: Full type support for new props
v1.0.x
🚀 Initial release with lazy loading and WebP conversion
🌫️ Auto blur placeholders
📱 Responsive image support
🤝 Contributing
Contributions are welcome! Please read our contributing guidelines.
📄 License
MIT © 2026 Yared Abebe
⭐ Support
If you find this package helpful, please consider:
⭐ Starring on GitHub
📢 Sharing on social media
🐛 Reporting issues
💡 Suggesting new features
🎯 Key Updates Made:
- SEO Features Highlight - New badge and section
- v1.1.0 Tag - Clear version indication
- Image SEO Props - License, author, credit, etc.
- Video SEO Props - Chapters, duration, transcript
- Key Moments Examples - Google video chapters
- Migration Guide - From v1.0.x to v1.1.0
- License Types - Complete list supported
- Google Search Examples - Visual preview of results
- Performance Metrics - Updated with SEO impact
- Changelog - New features listed
