Menu

1 / 2

How to Generate Link Previews Like Slack (Without the Edge-Case Hell)

DEV Community: api·bpmcginley·6 months ago
#75KWio7P
Reading 0:00
15s threshold

You've seen it a thousand times: you paste a URL into Slack, Discord, or iMessage and it blooms into a tidy card with a title, an image, and a description. It's one of the highest-trust little UI elements you can add to a chat app, a comment box, a CMS, or a bookmarking tool. A bare URL looks like spam. An unfurled link looks legit — and gets clicked.

So you decide to build it. How hard can it be? You fetch the page, grab a few meta tags, done by lunch.

Then reality shows up.

What a link preview actually is

The card is built from Open Graph tags in the page's <head> :

​

<meta property= "og:title" content= "The Verge" /> <meta property= "og:description" content= "Technology, science and culture." /> <meta property= "og:image" content= "https://.../cover.png" /> ​```

Read those, render a card. Simple — in the demo. The pain is everything *between* "fetch the page" and "read the tags."

## The five things that break your weekend scraper

1.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.