DEV Community

gleamso
gleamso

Posted on

7 Common OpenGraph Mistakes and How to Fix Them

Hey developers! πŸ‘‹ After helping hundreds of Gleam.so users with their OG images, I've noticed some common patterns. Here are the top mistakes and how to fix them.

1. Incorrect Image Dimensions πŸ“

The Problem

<!-- Common mistake -->
<meta property="og:image" content="https://example.com/image.png" />
<!-- Missing width/height -->
<!-- Using wrong dimensions like 800x600 -->
Enter fullscreen mode Exit fullscreen mode

One user shared:

"My images looked perfect on Twitter but were cropped weirdly on LinkedIn."

The Fix

<!-- Correct implementation -->
<meta property="og:image" content="https://example.com/og.png" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
Enter fullscreen mode Exit fullscreen mode

Pro Tip: Use 1200x630px as your default size. It works well across all platforms.

2. Text Readability Issues πŸ‘€

The Problem

// Common mistake: Not considering mobile view
const title = {
  fontSize: '32px',
  color: '#666666',  // Low contrast
  fontWeight: 'normal'
};
Enter fullscreen mode Exit fullscreen mode

User feedback:

"Text was unreadable when shared on mobile devices."

The Fix

// Text optimization
const titleStyle = {
  fontSize: '72px',
  color: '#000000',
  fontWeight: 'bold',
  lineHeight: 1.2,
  maxWidth: '80%'  // Prevent edge bleeding
};

// Contrast checker
const hasGoodContrast = (bg: string, text: string): boolean => {
  return calculateContrast(bg, text) >= 4.5;
};
Enter fullscreen mode Exit fullscreen mode

3. Missing Fallback Data πŸ”„

The Problem

<!-- Only including og:image -->
<meta property="og:image" content="/path/to/image.png" />
Enter fullscreen mode Exit fullscreen mode

User experience:

"When OG image failed to load, posts looked broken."

The Fix

<!-- Complete fallback chain -->
<meta property="og:image" content="https://example.com/og.png" />
<meta property="og:image:alt" content="Description of your content" />
<meta property="og:title" content="Your Title" />
<meta property="og:description" content="Your Description" />

<!-- Twitter-specific fallbacks -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:image" content="https://example.com/og.png" />
Enter fullscreen mode Exit fullscreen mode

4. Cache Issues πŸ”„

The Problem

// Image updates not reflecting
const ogImage = '/static/og-image.png';
Enter fullscreen mode Exit fullscreen mode

Common complaint:

"Updated my OG image but social platforms still show the old one."

The Fix

// Add version control
const getOGImageUrl = (baseUrl: string): string => {
  const version = Date.now();
  return `${baseUrl}?v=${version}`;
};

// Usage
<meta 
  property="og:image" 
  content={getOGImageUrl('https://example.com/og.png')}
/>
Enter fullscreen mode Exit fullscreen mode

5. Poor Performance ⚑

The Problem

// Generating images on every request
const generateOG = async (text: string) => {
  const svg = createSVG(text);
  const png = await convertToPNG(svg);
  return png;
};
Enter fullscreen mode Exit fullscreen mode

User feedback:

"OG image generation was slowing down my entire site."

The Fix

// Implement caching
const cachedGenerate = async (text: string) => {
  const cacheKey = createHash(text);
  const cached = await cache.get(cacheKey);

  if (cached) return cached;

  const image = await generateOG(text);
  await cache.set(cacheKey, image, '7d');

  return image;
};
Enter fullscreen mode Exit fullscreen mode

6. Broken URLs πŸ”—

The Problem

<!-- Relative paths -->
<meta property="og:image" content="/images/og.png" />
Enter fullscreen mode Exit fullscreen mode

Common issue:

"My OG images work locally but not in production."

The Fix

// Always use absolute URLs
const getAbsoluteUrl = (path: string): string => {
  const baseUrl = process.env.NEXT_PUBLIC_BASE_URL;
  return new URL(path, baseUrl).toString();
};

// Usage
<meta 
  property="og:image" 
  content={getAbsoluteUrl('/images/og.png')}
/>
Enter fullscreen mode Exit fullscreen mode

7. Missing Mobile Optimization πŸ“±

The Problem

// Desktop-only testing
const testOG = async (url: string) => {
  const response = await fetch(url);
  return response.ok;
};
Enter fullscreen mode Exit fullscreen mode

User experience:

"Images looked great on desktop but terrible on mobile shares."

The Fix

// Comprehensive testing
const testOGImage = async (url: string) => {
  const tests = [
    checkDimensions,
    checkMobileRendering,
    checkTextSize,
    checkContrast,
    checkLoadTime
  ];

  return Promise.all(tests.map(test => test(url)));
};
Enter fullscreen mode Exit fullscreen mode

Quick Fix Checklist βœ…

  1. Use 1200x630px dimensions
  2. Ensure text is 72px+ for titles
  3. Implement proper fallbacks
  4. Use absolute URLs
  5. Add cache busting
  6. Test on mobile
  7. Monitor performance

Need a Reliable Solution?

If you're tired of dealing with these issues, try Gleam.so.

I handle all these optimizations automatically, and you can now design & preview everything for free!

Share Your Experience 🀝

What OG image issues have you encountered? Drop them in the comments and let's solve them together!


Part of the Making OpenGraph Work series. Follow for more web development insights!

Top comments (0)