A fast, local-first "redirection engine" for !bang users with a few extra features ^-^ s.dunkirk.sh
v0.4.0 8bbf72e8 Kieran Klukas

v0.4.0 — The Service Worker rewrite 🪿

Halo! This is by *far* the biggest unduckified release pretty much ever. I did a near-total rewrite of how the redirect logic works and did a huge amount of performance work. It should be basically the same for most of yall except for a few nice new features :) Grab a coffee. There's a lot in this one. Before, every bang ran through this path: `!gi cats` -> load unduckified's page -> parse a ~1.5 MB JavaScript bang map -> run the redirect. Fast-ish! The page was cached as an SPA but you still had to pay the inital cost of downloading the huge bang map and then parsing it. Now a Service Worker intercepts the navigation before any page is even loaded by the browser. When you run a search the browser fires a request at `s.dunkirk.sh?q=%s`, the worker catches it in its `fetch` handler, resolves the bang, and answers with a `302` in under a millsecond. ```js // roughly what the worker does on every search: self.addEventListener("fetch", (event) => { const dest = resolveBang(query); // one hash probe into the binary catalog if (dest) event.respondWith(Response.redirect(dest, 302)); }); ``` The first search after install still downloads the catalog once however the catelog has been crazy optimized now so the total bundle size is ... wait for it ... `192KiBs` I benchmarked unduckified properly (headless Chrome, paired stats, permutation tests definitely go read [BENCHMARK.md](https://github.com/taciturnaxolotl/unduckified/blob/main/BENCHMARK.md) for the full details): | | warm search | cold first search | catalog on the wire | |---|--:|--:|--:| | **v0.4.0** | **~1 ms** | ~217 ms | **192 KiB** | | v0.3.x (the old page) | ~22 ms | ~290 ms | 330 KiB (1.5 MB decoded) | Warm searches went from ~22 ms to ~1 ms because there is nothing to render or parse anymore: the service worker just runs a hash lookup and a redirect. Against flashbang (the other Service-Worker bang tool out there which actually inspired this rewrite!): we're *tied warm, and ~34 ms faster cold** (p < 0.001). We even beat DuckDuckGo's *cold* first search, despite DDG downloading nothing and us downloading a whole catalog. 🪿 The catalog used to be JavaScript your browser re-parsed on every load. Now it's a purpose-built binary (`bangs.bin`) with **zero decode step**. The worker is able to read it straight through typed-array views. It's a **minimal perfect hash**, so a trigger goes to its entry in a single probe with no hashmap in memory. Each entry stores a 2-byte checksum instead of the full trigger string (verifying a lookup without paying to store 13,000+ strings), and URLs are inlined so brotli can crush the shared `https://…/search?q=` bits. Cloudflare only auto-compresses at brotli quality ~4, so we ship the catalog **pre-compressed at brotli-11** and tell CF to just serve it directly: ``` /bangs.bin Content-Encoding: br Cache-Control: public, no-cache, no-transform ``` Your browser's `fetch()` decodes it without any extra work on our side, and we shave ~15% off the wire for free! ```console $ curl -sI -H 'Accept-Encoding: br' https://s.dunkirk.sh/bangs.bin | grep -i content- content-encoding: br content-length: 196997 ``` Point your browser's suggestions field here and unduckified will complete bangs itself: ``` https://s.dunkirk.sh/suggest?q=%s ``` Type `!git` and you'll get `!github`, `!githubdocs`, and friends, ranked by popularity. By default (to be a bit more privacy conscious) it *only* completes bang names and nothing else. If you want more you can opt into a few more features: ``` https://s.dunkirk.sh/suggest?q=%s&forwarder=ddg https://s.dunkirk.sh/suggest?q=%s&site_specific_forward=1 ``` Upgrading from the old version? Your **search count, custom bangs, and default bang** migrate automatically on first load! (The search counter moved into the worker's storage; the migration is idempotent so it can't double-count, even across tabs.) - **Save & restore your config**: export your settings and custom bangs to a file and import them back. - **Edit** custom bangs not just add and delete them. - `!settings` now actually **opens the settings panel** (and `!` still just takes you home). - Fixed redirects failing in some cases, plus default-bang and trailing-bang (`gh!`) handling. - Fixed cache invalidation so a new catalog is picked up exactly when it changes and never re-downloaded when it doesn't. - The landing UI and its sound effects no longer load on the redirect path — a bang query fetches only what it needs (catalog + resolver, in parallel) and gets out of the way. - Compressed the goose. 🪿 --- Thanks for using unduckified, and huge thanks to everyone who filed bangs and suggestions. Go forth and `!` responsibly. xoxo 🪿

No message

No message