Pandyland

A better Pandyland random comic generator, by Magnus Hoff

Pandyland is a fantastic web comic. You should read it. One day, instead of releasing a new comic, a random comic generator was revealed.

The random comic generator is an entertaining and addictive time sink, but it could be a more efficient time sink. It works by selecting three panels randomly and presenting them as if they were made as one comic. The random selection happens on the server side and you can ask to get a permalink to a given randomly generated comic.

There are two problems with the current generator, both of which are caused by having the comic be generated on the server side. The first problem is that it costs a round trip to ask for the next comic. When this happens, the server has to generate the entire page with the random comic. My local measurements seem to find this takes about 650ms, way above noticable. This is just the page that contains the comic and does not take into account the time required for downloading the panels.

By a simple scheme, a permanent URL is generated for each comic. When the comic is generated on the server, this URL cannot be known before the request is sent, so the URL in the address bar does not represent the comic being displayed. As you generate a new comic, you can therefore not navigate backwards in you browser history to get to the last one you saw. This is the second problem.

I wrote a new generator which solves the second problem by generating the comic on the client side. When the "generate"-link is clicked, the page generates a URL for a new comic and navigates to it by assigning this URL to window.location. This way, you can always navigate back in your browser history to find a previous comic. As the page is loaded, the script on the page inspects the URL and opens the corresponding comic in an embedded <iframe> element.

This scheme incurs two page loads for each new comic. By using the History API, when it is available, we can get this back to one page load, both when generating a new comic and when navigating through the history.

Fixing the last page load would require editing the official page, which I don't have access to, or embedding the comic panels directly, which I am not allowed to. The scheme I have arrived at lets the comic site display all the advertisements that usually accompany the comic.

Go see the new and improved generator and click generate till you drop!

Magnus Hoff, 2015