emptygif
Language: English

All languages and frameworks

React Router (framework mode, ex-Remix) TypeScript

A TypeScript snippet for React Router (framework mode, ex-Remix) that answers requests for /pixel.gif with the empty GIF, decoded once at startup.

React Router (framework mode, ex-Remix) TypeScript

Install
npx create-react-router@latest
File
pixel.ts
Run
npm run dev
// app/routes.ts:  route('/pixel.gif', 'routes/pixel.ts')
// app/routes/pixel.ts - a resource route: a loader and no default export.
const GIF = Uint8Array.from(atob('R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='), (c) => c.charCodeAt(0));

export function loader() {
  return 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: React Router (framework mode, ex-Remix)

More in TypeScript