emptygif
Language: English

All languages and frameworks

Cloudflare Workers TypeScript

A TypeScript snippet for Cloudflare Workers that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

Cloudflare Workers TypeScript

Install
npm create cloudflare@latest
File
index.ts
Run
npx wrangler dev
// src/index.ts
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export default {
  fetch(request) {
    if (new URL(request.url).pathname !== '/pixel.gif') {
      return new Response('Not Found', { status: 404 });
    }
    return new Response(GIF, {
      headers: { 'Content-Type': 'image/gif', 'Cache-Control': 'no-store' },
    });
  },
} satisfies ExportedHandler;

We ran this snippet and compared the bytes it returned.

Check it

curl -sI http://localhost:8080/pixel.gif

Official site: Cloudflare Workers

More in TypeScript