← All posts

· #cloudflare #performance

Notes on rendering at the edge

Running SSR on Workers changes a few assumptions you may carry over from a traditional Node server.

Environment variables are per request

On Workers, bindings and variables are injected for each request. Reading process.env.SOMETHING at module scope gives you undefined. Read env inside a server function handler, or import env from cloudflare:workers.

Bundle what you can

Content that rarely changes — like these posts — can be bundled into the Worker at build time. There is no filesystem at runtime, so fs.readFile is out; Vite's import.meta.glob does the job at build time instead.

Cache deliberately

Public, identical-for-everyone responses (like an RSS feed) can carry Cache-Control: public. Anything personalised should not.