emptygif
Language: English

All languages and frameworks

SvelteKit TypeScript

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

SvelteKit TypeScript

Install
npx sv create
File
+server.ts
Run
npm run dev
// src/routes/pixel.gif/+server.ts
import type { RequestHandler } from './$types';

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

export const GET: RequestHandler = () =>
  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: SvelteKit

More in TypeScript