Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good resources for extreme minified JavaScript (js1k-style)

As I'm sure most of the JavaScripters out there are aware, there's a new, Christmas-themed js1k. I'm planning on entering this time, but I have no experience producing such minified code. Does anyone know any good resources for this kind of thing?

like image 800
Skilldrick Avatar asked Nov 27 '10 14:11

Skilldrick


People also ask

What is the best JavaScript Minifier?

UglifyJS is one of the most popular JavaScript minification tools. It can parse, minify and compress JavaScript code. Besides, the tool generates a source map file while compressing to track back to your original code.

Is minified JavaScript faster?

Some of the many benefits of minifying your CSS and JavaScript include a greatly reduced file size, which will be quicker to load on your website or blog. You also get better compression for the code, which will make it smaller and faster to load in general, even without minification.

What is minified version of JavaScript file?

Minification, also known as minimization, is the process of removing all unnecessary characters from JavaScript source code without altering its functionality. This includes the removal of whitespace, comments, and semicolons, along with the use of shorter variable names and functions.


1 Answers

In the following link you'll find surprisingly good tricks to minify js code for this competition:

http://www.claudiocc.com/javascript-golfing/

One example: (extracted from section Short-circuit operators):

if (p) p=q;  // before
p=p&&q;      // after

if (!p) p=q; // before
p=p||q;      // after

Or the more essoteric Canvas context hash trick:

// before
a.beginPath
a.fillRect
a.lineTo
a.stroke
a.transform
a.arc                                  

// after
for(Z in a)a[Z[0]+(Z[6]||Z[2])]=a[Z];
a.ba
a.fc
a.ln
a.sr
a.to
a.ac

And here is another resource link with amazingly good tricks: https://github.com/jed/140bytes/wiki/Byte-saving-techniques

like image 193
higuaro Avatar answered Nov 06 '22 07:11

higuaro