Cloudflare Pages Functions TypeScript
A TypeScript snippet for Cloudflare Pages Functions that answers requests for /pixel.gif with the empty GIF, decoded once at startup.
Cloudflare Pages Functions TypeScript
// functions/pixel.gif.ts (the file path is the route)
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));
export const onRequestGet: PagesFunction = () =>
new Response(GIF, {
headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
});
We ran this snippet and compared the bytes it returned.
Check it
curl -sI http://localhost:8080/pixel.gif
Official site: Cloudflare Pages Functions