Show HN: Flashbang – Sub-1ms DuckDuckGo bang redirects via Service Workers

  • Posted 5 hours ago by t3ntxcles
  • 1 points
https://github.com/ph1losof/flashbang
I liked DuckDuckGo's bangs (shortcuts like !g to search Google directly) but didn't want to use DuckDuckGo as my search engine and the bang redirects were slow. Projects like unduck solved this by redirecting bangs locally — but they all load a webpage, execute JavaScript, then call window.location.replace(). Searches had a visible flash before the redirect. Every alternative I've tested — whether it's a page-load redirect, a Cloudflare Worker, or a browser extension — adds measurable latency. I knew a Service Worker could solve this entirely — intercept the request before the browser renders anything. So I built my own tool.

Flashbang intercepts the request at the Service Worker level before the browser renders anything. The SW does a hashmap lookup and a string template fill on raw URL-encoded bytes. Median redirect latency is sub-1ms. The browser never loads a page.

How it works:

- Service Worker intercepts every search request before it becomes a navigation and before page starts loading

- Bang parsing operates on raw encoded strings — no decodeURIComponent, no regex, no new URL() in the hot path

- Supports all 7 DuckDuckGo bang syntax patterns (prefix, suffix, no-space, mid-query, etc.)

- 14,000+ bangs from DDG + Kagi, plus custom bangs

- Address bar autocomplete via OpenSearch with a radix trie, ranked by frecency (exponential decay, 14-day half-life)

- Once the SW is installed, redirects work fully offline

What it's not:

- Not a browser extension — it's a web app you set as your default search engine

- No tracking, no analytics, no telemetry

- Zero runtime dependencies

- AGPL-3.0

~2,600 lines of TypeScript, 1,200 lines of tests. I'd love feedback on the architecture.

https://github.com/ph1losof/flashbang

1 comments

    Loading..