How To Code A 5k Entry
1
Get Inspired
Check out entries for 2000 and 2001. This should give you an idea of what is possible as well as a general idea of what to attempt yourself. If you are looking to win, pay attention to what the judges picked and didn't pick. Choose something you will enjoy doing - you'll be working on it for a while.

Step 2
2
Write Code Normally
Don't try to write tiny code yet; concentrate on getting the code to work. Keep your code structured and readable. Use function and variable names you will understand (long, unique names will avoid problems later). Include comments. Once the code works, you can start to compress it.

Step 3
3
Optimize The Code
Create variables to replace multiple references. Pull out repeated statements as functions. Remove superfluous braces around single statement loops and ifs. If possible, rewrite if structures with ternary operators. Remove HTML tags and attributes that aren't needed. Remove quotes around HTML attribute values if the values don't include spaces. Test after every change and keep backups.

Step 4
4
Minimalize Identifiers
Replace each variable and function name with 1 or 2 letters. Use your editor's search and replace feature. Keep a dictionary of your replacements. Test after every change and keep backups.

Step 5
5
Remove Formatting
Make sure all JS statements end with a semi-colon. Remove comments and blank lines first. Then whitespace and indenting. Remove all newlines to create a single line file. Applications like BrainJar's Crunchinator and DOMAPI's JSCruncher can do this for you. Test after every change and keep backups.

Step 6
6
Create a Self-Extracting Archive
Before compressing, make sure your code doesn't use either ~ or `. Copy and paste your code into the textarea below and press the "Compress" button. The compression process will take a while (about 1 minute per 1k). You can watch it's progress in your browser's status bar. The resulting, compressed file is a self-extracting archive that, when viewed in a browser, will uncompress and run itself. The compression mechanism looks for repeated strings and substitutes tokens for those strings. You can set a maximum string replacement length - lower values will speed compression but may not optimally compress your file. Because the self-extraction code is added to the compressed code, some pre-optimized, sub-1k files will grow in size when run through the compressor.
Original code:

Max replacement string length:


Compressed code:

Compressed size: bytes
If the compressed code is greater than 5k, you'll have to return to step 2, drop some functionality and repeat the compression steps.

Though the self-extraction accurately recreates the original code, browsers appear to parse dynamically created code differently than static code. Infrequently, some scripts may lose some functionality after compression. But most don't.

And, yes, this entry has been compressed using itself - 5588 bytes to 4657 bytes.