emptygif
Language: English

All languages and frameworks

Astro TypeScript

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

Astro TypeScript

Install
npm create astro@latest
File
pixel.ts
Run
npm run dev
// src/pages/pixel.gif.ts  (on-demand rendering needs a server adapter in production)
import type { APIRoute } from 'astro';

export const prerender = false;

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

export const GET: APIRoute = () =>
  new Response(GIF, {
    headers: {
      'Content-Type': 'image/gif',
      'Content-Length': String(GIF.length),
      '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: Astro

More in TypeScript