I absolutely loved this bit from Marco Arment’s recent interview w/ Rands:
The [Instapaper] bookmarklet has a mechanism to save pages from sites that require logins…
The way it does this is ridiculous: instead of calling a simple GET request to save the page, since an entire page’s contents would quickly overrun any URL-length limits in the stack, it injects a FORM with a POST action and populates a hidden value with the page contents.
But form-data requests from browsers aren’t Gzip-compressed, so the resulting data is huge and needs to be sent over people’s (often slow, often mobile) upstream connections. So I found an open-source DEFLATE implementation in Javascript — really — and the bookmarklet compresses the page data right there in the browser before sending it.
The whole procedure is hideously complex, but works incredibly well.
…awesome. This is the type of crap that makes me feel better about all the crap code that I write. Marco’s code obviously isn’t “crap”…not by a long shot…it’s the type of great hack that, at first consideration, makes a developer (or at least me) go, “Well that’s not going to work. It’s gonna break on this browser and that phone and god this is a mess screw it.”
And then you try it, and it seems to pretty much work so far at least during testing, and you launch it and have pictures in your head of the world exploding out there as your mess of an idea doesn’t work in a million situations both imagined and unimagined.
Marco’s bookmarklet-that-grabs-all-your-HTML-and-plops-a-form-in-your-page-and-DEFLATEs-the-HTML-in-your-browser-all-with-javascript-and-submits-the-form is a key ingredient to a great service used by many who are completely unaware of the hack’s existence. It’s a reminder of all the times that messy solutions do work and make users happy even when the creator knows that the code is “ridiculous.”