Link previews from one edge Worker · Sep – Oct 2026
Rich previews for payment links, on a static page
Merchants share payment links in chats and on social media. Every one of those links showed the same generic preview, so the person receiving it couldn’t tell who was asking to be paid, or for what. The page itself is a static app served by nginx, which can’t write per-link tags. A Cloudflare Worker in front of it does that instead.
- Role
- Frontend engineer
- When
- Sep – Oct 2026
- Where
- PayGlocal
- Stack
- Cloudflare WorkersnginxOpen GraphJavaScript
The situation
Link previews come from Open Graph tags: a few lines in a page’s HTML that chat apps and social sites read to build the little card under a link. Their crawlers fetch the HTML and don’t run JavaScript, so a single-page app can’t set those tags from the browser. Our payment page was exactly that: one static index.html served by nginx for every link. To show the right merchant and amount, something had to change the HTML for each link before it left the server, and nginx had no clean, modern way to do that per request.
What I built
- Placeholder Open Graph tags in the page’s static HTML: a title, description and image that make a sensible generic preview on their own.
- A dedicated domain for payment links, routed through a Cloudflare Worker. Every other request skips the Worker and goes straight to our servers.
- The Worker fetches the normal page from our server and, alongside it, the link’s details from our payment link API.
- It finds the placeholder tags with a regular expression, replaces them with the link’s details, and streams the page on to whoever asked.
- The page people actually use is unchanged: the same static app, the same server, the same deploy. Only the HTML head differs per link.
What the person receiving the link sees
Hi! Here’s the link for the invoice pay.example.com/l/8fK2q
Every link looked the same, so a customer couldn’t tell a real request from a generic page.
The preview names who is asking and for how much, before anyone taps. (Sample data.)
The path a preview request takes
- 1Chat app
Someone pastes a payment link. The app’s crawler fetches the URL to build a preview. It reads the HTML and never runs JavaScript.
- 2Cloudflare Worker
Payment links live on their own domain, which routes to a Worker. Every other request goes straight to our servers, untouched.
- 3Our server (nginx)
Returns the same static page as always, with placeholder Open Graph tags already in its head.
- 4Payment link API
The Worker asks for this link’s details: who is asking to be paid, and what for.
- 5Back through the Worker
It finds the placeholder tags with a regular expression, swaps in the real details, and streams the page on.
- 6Chat app
The crawler reads real tags and shows a preview of the actual payment request.
Decisions
Do it at the edge, not in nginx
Rewriting HTML per request in nginx means modules and config nobody wants to maintain. A Worker is a small piece of JavaScript in front of the site, deployed separately, with its own logs.
Placeholders that work on their own
The static page already carries generic Open Graph tags. If the Worker can’t fill them in, the preview still looks like a proper payment page instead of a bare URL.
Only payment links pay the cost
Routing by domain means the Worker and the extra API call happen only for links that need a preview. The rest of the site behaves exactly as before.
Stream, don’t rebuild
The Worker passes the page through, changing a few tags as it goes, rather than holding the whole response and rebuilding it. The page reaches people as quickly as it did before.
Outcome
| What | Before | After | Detail |
|---|---|---|---|
| Preview of a shared payment link | generic | merchant and amount | per link |
| Changes to the payment page itself | placeholder tags only | same app, same deploy | |
| Requests that go through the Worker | payment-link domain only | rest untouched | |