Ingenious games in just 13KB of JavaScript

Last Spartan screenshotI’m not fond of JavaScript but I am still in awe at the ingenuity of people who created a HTML5 game in JavaScript in just 13KB. There’s an annual competition called Js13K and this year there were 220 entries and prizes of $20,000 in total.

When you think that many graphics are way bigger than 13KB this is even more of an accomplishment. It means those games have to mostly draw their own. graphics rather than use prerendered graphical images. It helps that HTML5 includes a canvas drawing area and instructions in JavaScript to draw into it.

The GitHub Blog featured the top ten from this years competition. The picture comes from The Last Spartan which I really liked. Ironically the screen grab image was 121KB, almost eight x the size of the actual game!

If you are ever stuck for ideas for games, take a look at these. Being JavaScript, you can right-click in your browser and View Source (Chrome) or View Page Source (Firefox). Of course, to achieve 13KB, many of them have been minified which means getting rid of all spaces, carriage returns and renders it rather unreadable. This is what it looks like.

Screenshot of last Spartan source code

However the internet taketh and the internet giveth. If you paste this (or any of the source listings) into an online deminifier (aka beautifier) such as then you get all 1622 lines laid out in immaculately indented glory.  It’s actually 73KB in size as a normal listing and still very impressive.

There’s no reason why games can’t be done this way i.e. drawing graphics in C+SDL2 though I doubt I’d get them down to 13KB. My asteroids game which was 2200 lines of C generates a 96 KB exe. But when you add in images, SDL code and sounds etc it comes out at just under 35 MB.

Leave a Reply

Your email address will not be published. Required fields are marked *