Gitvurl

Gitvurl AI Studio/Oct 4, 2026/5 min read

Why a Relative `og:image` Breaks GitHub, Discord, and Slack Cards

Relative `og:image` paths can cause link previews on platforms like GitHub, Discord, and Slack to fail. This article explains why and provides the solution for proper rich embed rendering.

Open Graphlink previewsGitHub embedsDiscord unfurlsSlack embedsrelative vs absolute URLs

When you're developing a web application, especially one that involves sharing links across different platforms, you often encounter the need for rich link previews. These previews, also known as link unfurls or embeds, enhance the user experience by displaying an image, title, and description directly within platforms like GitHub, Discord, and Slack. The magic behind these previews lies in Open Graph (OG) metadata, a set of meta tags you include in the <head> section of your HTML.

The og:image tag is crucial for specifying the preview image. However, a common pitfall developers run into is using a relative URL for og:image. While relative URLs work perfectly fine within your own website's navigation, they can cause link previews to break on external platforms. This article will delve into why this happens and how to correctly implement absolute URLs for your og:image to ensure your link cards display as intended everywhere.

Open Graph is a protocol developed by Facebook that allows any web page to become a rich object in a social graph. When a platform like GitHub, Discord, or Slack encounters a link, it crawls the provided URL to extract specific meta tags from the HTML. The most important ones for link previews are:

  • og:title: The title of your content.
  • og:description: A brief description of your content.
  • og:image: The URL of the image to be displayed.
  • og:url: The canonical URL of your page.
  • og:type: The type of object (e.g., 'website', 'article').

These tags inform the sharing platform what information to present in the preview. Without them, or with improperly formatted ones, the platform has no way to generate a meaningful preview, often resulting in a broken or generic embed.

The Pitfall of Relative `og:image` URLs

Let's consider an example. Suppose you have an image located at /images/preview.jpg within your web application's directory structure. You might be tempted to set your og:image tag like this:

<meta property="og:image" content="/images/preview.jpg">

This works flawlessly when a user is browsing your site and sees the image displayed. However, when a platform like Discord or GitHub tries to unfurl a link to your page, it performs a request to your server for that URL. The problem arises because the crawler doesn't have a base URL context in the same way a browser does when rendering your page. It receives your HTML, sees /images/preview.jpg, and tries to resolve this relative path. Without a clear base URL from which to construct the full path, the crawler often cannot find the image, leading to the preview failing to render the image or the entire card.

Think of it like sending a letter with only a street name but no city or country. The postal service can't deliver it. Similarly, when a crawler fetches your page, it needs a complete, absolute URL to locate the og:image resource.

Why Absolute URLs are Essential for External Crawlers

External services that generate link previews operate by fetching your web page's content. They request the HTML from the URL you've shared. When they parse this HTML, they look for the Open Graph meta tags. For the og:image tag, they require a full, absolute URL. An absolute URL includes the scheme (http or https), the domain name, and the path to the resource.

For instance, if your website is hosted at https://www.example.com and your image is at /images/preview.jpg, the correct absolute URL for og:image would be:

https://www.example.com/images/preview.jpg

This is unambiguous. The crawler knows exactly where to find the image. Platforms like GitHub, Discord, and Slack are designed to handle these absolute URLs, ensuring they can reliably fetch and display your preview images.

Implementing Absolute URLs in Your Next.js Application

For developers using modern frameworks like Next.js, managing OG tags is often done dynamically. You can set these tags in your _document.js or _app.js files, or more commonly, within the head component of individual pages or layouts.

Here's an example of how you might set up your Head component in a Next.js page to include absolute OG tags:

import Head from 'next/head';

function MyPage() {
  const siteUrl = 'https://www.example.com'; // Replace with your actual domain
  const pagePath = '/my-specific-page'; // The path of the current page
  const imageUrl = '/images/social-preview.jpg'; // Your image relative path

  return (
    <Head>
      <title>My Awesome Page Title</title>
      <meta property="og:title" content="My Awesome Page Title" />
      <meta property="og:description" content="This is a great page with amazing content!" />
      {/* Ensure the og:image is an absolute URL */} 
      <meta property="og:image" content={`${siteUrl}${imageUrl}`} />
      <meta property="og:url" content={`${siteUrl}${pagePath}`} />
      <meta property="og:type" content="website" />
      {/* Add other meta tags as needed */} 
    </Head>
  );
}

export default MyPage;

In this Next.js snippet, siteUrl holds your domain, and imageUrl holds the relative path to your image. By concatenating them, you construct the absolute URL that Next.js will render in the HTML's <head> section. This ensures that crawlers will find a complete and valid URL for your og:image.

It's also good practice to make your siteUrl configurable, perhaps through environment variables, especially if you're deploying to different environments (development, staging, production). This prevents hardcoding sensitive or environment-specific information.

Verifying that your OG tags are correctly configured is essential before sharing links widely. Fortunately, there are tools available to help you.

  • Card Validation Tools: Many services allow you to paste a URL and see a preview of how it will look on various platforms. These tools fetch your page and report any issues with your OG tags.
  • Platform-Specific Debuggers: Some platforms offer their own debuggers or validators. For example, Facebook has a Sharing Debugger, though it's primarily for Facebook. The general principle remains: these tools simulate the crawling process.
  • URL Preview Services: Services like Gitvurl are specifically designed to help developers preview and debug their link unfurls across multiple platforms. You can input your URL into Gitvurl to see exactly how GitHub, Discord, Slack, and others will render it, helping you catch issues like broken og:image URLs before they impact your users.

When testing, always check the rendered image, title, and description. If the image is missing or a generic placeholder appears, it's a strong indicator that your og:image URL is not correctly formatted or resolvable.

Hashtags · 6

Open Graph link previews GitHub embeds Discord unfurls Slack embeds relative vs absolute URLs

Create your first AI Ad on GitvurlStart