emptygif
Language: English

All languages and frameworks

Netlify Functions TypeScript

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

Netlify Functions TypeScript

Install
npm i -D @netlify/functions
File
pixel.mts
Run
netlify dev
// netlify/functions/pixel.mts
import type { Config } from '@netlify/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 Functions

More in TypeScript