Settings

Theme

Show HN: I made a Cloudflare Worker that injects OpenGraph data into a React SPA

gitlab.com

2 points by alexgleason 3 years ago · 2 comments · 1 min read

Reader

The worker requests the public API in the background, intercepts requests to React pages and injects OpenGraph tags into them.

Before you tell me to use Next.js, I know. But I think Cloudflare Workers are really cool!

TIPSIO 3 years ago

Great job!

> Before you tell me to use Next.js, I know. But I think Cloudflare Workers are really cool!

It is really cool. I like to think sometimes there's no right way to do things so long it works for you.

For example, imagine an org/biz with a slow or busy dev team. Meta tags and SEO are constantly updating, pixels need to be dropped by marketing, stuff needs to be injected into the head, etc... This allows them to do so independently at a lower level.

Obviously the trade-off is this opens up to breaking things. Or, I'm not sure why they wouldn't use a Tag manager, but I am just saying out there this probably makes sense for someone.

> const body = text.replace(PLACEHOLDER, html);

I really need to learn Typescript... but I think this is where you update. This could break/timeout if the page is gigantic. A faster strategy would be to use their HTML Rewriter. [1]

[1] https://developers.cloudflare.com/workers/runtime-apis/html-...

gepeake 3 years ago

Just FYI, the new wrangler supports direct typescript support including minification so webpack isn’t necessary anymore

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection