I recently did a little experiment to see how small (in bytes) I could make useful valid HTTP responses for a particular use case.
On my homepage, I have a little feature where I display the names of the last song I listened to and the last movie I watched. I’ve implemented that via a bit of JavaScript that fetches that information from a pair of Lambda functions that make requests to Last.fm and Letterboxd.
I use that client script as a place to play some code golf with myself, trying to achieve the functionality with as few JavaScript tokens as possible.1 Every few months, I think of a way to shrink it further. Here’s what I’ve got as of the writing of this post (source):
The script currently has two async calls: fetch() and response.text(). The first one resolves once the HTTP response’s headers have been received and the second resolves once the body has been received.
The fetch() will be difficult-to-impossible to remove, but the response.text() one is a bit more avoidable! My first thought was to put my response data in an HTTP response header, but then I realized I could go further and extend my code golfing to the HTTP response itself, putting the data directly into the status text.