3 ms·
I fired up Chrome's dev tools to figure out how it works. The JS that's doing the work is at http://imgs.xkcd.com/static/waldo.js http://imgs.xkcd.com/static/w
by dkulchenko 15y ago
I fired up Chrome's dev tools to figure out how it works.
The JS that's doing the work is at http://imgs.xkcd.com/static/waldo.js http://imgs.xkcd.com/static/waldo.js. On page load, it sends a GET request to http://umwelt.xkcd.com/story/ghenkEggov8 http://umwelt.xkcd.com/story/ghenkEggov8 with params w for the browser width in pixels, h for the height and r with the referrer. The rest of the qualifiers (geoloc and browser (user-agent)) can be determined on the server-side.
As a response, you get back JSON with the alt-text, image URL, and positioning info, which is then used to fetch and position the image.
Fun fact: the server-side is written in Haskell:
$ wget -S http://umwelt.xkcd.com/story/ghenkEggov8
--2012-04-01 11:26:41-- http://umwelt.xkcd.com/story/ghenkEggov8
Resolving umwelt.xkcd.com... 208.118.225.100
Connecting to umwelt.xkcd.com|208.118.225.100|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: Warp/1.1.0.1
Content-Type: application/javascript
Access-Control-Allow-Origin: *
Transfer-Encoding: chunked
Connection: close
http://hackage.haskell.org/package/warp/ http://hackage.haskell.org/package/warp/
Well done Randall and davean.