Skip to content
Website logo depicts

I to create appealing stuff

JavaScript Tetris in 1.5 KB

— Posted in Games | Reading time: 1 minutes

Around the time (2004) it was the probably the fastest Tetris in JavaScript available.

Other versions used absolute positioned images or DIVs to make up the blocks.

Using a <table> as a grid seemed logical.

I experimented with different methods of accessing the table (document.getElementsByTagName('td'), nextSibling) to iterate through the cells. Accessing it by table.rows[y].cells[x] was almost as fast as nextSibling but more convenient in terms of code-size.

Nowadays you can bring it down to 1 KB or even 512 bytes, but I did not want to give up on the scoring system, preview and VIM-bindings :-)

You can play it here: /games/javascript-tetris-1.5kb/jstetris.html. Use cursor keys or I, J, K, L, SPACE to control the game.