Sub topic 3
Social Crawlers and Server-Rendered HTML
Assume you know basic HTML, absolute URLs, HTTP requests, and server-side templates. This chapter focuses on what crawlers receive before a browser runs JavaScript.
Social crawlers and server-rendered HTML
When someone shares a URL, a platform usually sends an HTTP request to that URL. Its crawler reads the returned HTML and looks for Open Graph tags in the <head> element.
The crawler may not run your client-side JavaScript. Therefore, the final preview data must be present in the initial server response. A browser showing the correct title does not prove that a social crawler can see it.
Testing previews and refreshing caches
Inspect the HTML that a crawler receives:
curl -s -A "facebookexternalhit/1.1" https://example.com/cold-coffee \
| grep -i 'property="og:'Check that the response is successful, the tags are inside <head>, and the values describe the requested page. Platform preview tools can show parsed fields and may provide a way to request a fresh fetch. Caches differ by platform, so changing a tag might not change an existing preview immediately.
Object types and article properties
Use website for a general page. Use article for a published article, then add article-specific fields.
<meta property="og:type" content="article">
<meta property="article:published_time" content="2026-11-01T09:00:00Z">
<meta property="article:author" content="https://example.com/authors/jane">
<meta property="article:tag" content="coffee">Choose the type that matches the page rather than adding every available property.
Generating tags per page safely
Dynamic pages should generate metadata from page data. Escape every value before inserting it into HTML.
function escapeHtml(value) {
return String(value)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
.replace(/"/g, """);
}
function openGraphTags({ title, description, url, image }) {
return [
["og:title", title],
["og:description", description],
["og:type", "website"],
["og:url", url],
["og:image", image],
]
.map(([property, content]) =>
`<meta property="${property}" content="${escapeHtml(content)}">`
)
.join("\n");
}Common pitfalls and troubleshooting
- JavaScript adds tags after loading, but the crawler reads the original HTML.
- A relative or inaccessible image produces a missing preview image.
- Multiple conflicting
og:titleorog:imagetags can cause unpredictable selection. - A page returns a login screen, redirect, or error to the crawler.
- Caches preserve old metadata after the source has changed.
- Unescaped titles containing quotes can break the tag markup.
Exercise
A browser displays the correct page title, but curl shows no og:title. What should you investigate first?
Show answer
Check whether the title is added only by client-side JavaScript. Generate og:title in the server-rendered HTML inside the document head, then request the page again with curl.