Unduck and the Quest for the Zero-Latency Redirect

How a minimalist middleware engine uses data-as-code to outrun the giants of search.

t3-content/unduck

A heavily crosshatched ink illustration of a librarian holding a massive index book, pointing a reader directly to an exit door without needing to consult a central desk.
By shifting the redirect logic entirely to the client, Unduck eliminates the server round-trip.

Key Takeaways

The 100ms Tax

For power users, search engine "bangs" are muscle memory. Typing !w for Wikipedia or !gh for GitHub into DuckDuckGo saves seconds of clicking. But that convenience comes with an invisible performance tax. Every bang requires a full round-trip to a remote server, only for that server to issue an HTTP redirect back to the client.

In an era of highly optimized frontends, this DNS and time-to-first-byte latency feels sluggish. Unduck proposes a radical alternative. The fastest way to handle a request is to never send it to a server at all.

The architectural difference between a server-side redirect (top) and Unduck's local-first routing (bottom).

Data as Code: The 2.6MB Dictionary

To eliminate the server, Unduck must know where to send every possible query. The solution is an exercise in brute force. The repository contains a massive TypeScript file, src/bang.ts, weighing in at over 2.6 megabytes. This file hardcodes thousands of DuckDuckGo bangs directly into the application bundle.

Shipping a multi-megabyte JavaScript payload to save 100 milliseconds might sound counterintuitive. However, this is where modern web architecture flips the script. By treating data as code, Unduck leverages the browser's aggressive caching mechanisms.

const url = new URL(window.location.href);
const query = url.searchParams.get("q")?.trim() ?? "";
const match = query.match(/!(\S+)/i);
const bangCandidate = match ? match[1].toLowerCase() : null;

The Zero-Server Stack

Unduck is built with Vite and relies heavily on Progressive Web App (PWA) standards. Once a user visits the site, a Service Worker installs the logic locally. Subsequent searches do not even hit the network for the redirect phase.

With service workers we can intercept the `fetch` request, before the index.html gets rendered/loaded. One should (in theory) be redirected some micro-seconds faster than doing the redirect in the index.html js

This architecture transforms a web page into a piece of local infrastructure. It acts as middleware sitting directly in the browser's omnibox, intercepting queries before they ever leave the machine.

Local vs. The World

The performance benefits become obvious when comparing network waterfalls. The traditional approach pays the TLS and DNS tax twice: once for the search engine, and once for the final destination.

PhaseServer-Side (DuckDuckGo)Client-Side (Unduck)
DNS ResolutionRequired (~20-50ms)Skipped (Local Cache)
TLS HandshakeRequired (~50-100ms)Skipped
Routing LogicRemote ServerLocal JS Runtime
Total Latency to Redirect~150ms+~5ms
A split screen illustration. On the left, a message in a bottle is tossed into a vast, turbulent ocean. On the right, a person simply flips a light switch in a room that is already illuminated.
Server-side redirects rely on distant infrastructure, while client-side routing acts instantly on local state.

By embracing static deployment and aggressive local caching, Unduck proves that sometimes the best backend is no backend at all. It is a highly specialized tool that perfectly executes a single, vital function.