emptygif
Language: English

All languages and frameworks

Netlify Edge Functions TypeScript

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

Netlify Edge Functions TypeScript

File
pixel.ts
Run
netlify dev
// netlify/edge-functions/pixel.ts  (runs on Deno at the edge)
import type { Config } from '@netlify/edge-functions';

const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export default () =>
  new Response(GIF, {
    headers: {
      'Content-Type': 'image/gif',
      'Content-Length': String(GIF.length),
      'Cache-Control': 'no-store',
    },
  });

export const config: Config = { path: '/pixel.gif' };

We ran this snippet and compared the bytes it returned.

Check it

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

Official site: Netlify Edge Functions

More in TypeScript