Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do jQuery library scripts have no space between each other's line?

Tags:

jquery

If you ever opened and looked inside any jQuery library file, you must have seen that it has no space between its lines. It is unusual for most of us who generally code line by line that make it comfortable to read. What I found is it looks like reading an article with no meaning :).

So, what is the reason for jQuery's developers to make it like that? Would not it be convenient if it was written line by line?

like image 604
Abednego Avatar asked Mar 15 '12 17:03

Abednego


4 Answers

It's minified. It makes the file smaller, meaning faster websites.

All of the code is available in two formats:

  • Compressed (which allows you to have a significantly smaller file size) and
  • Uncompressed (good for debugging and to understand what is behind the magic).

From Downloading jQuery. A typical Software Engineering practice is to use full versions of code for development, and minified versions in production.

like image 93
calebds Avatar answered Nov 20 '22 14:11

calebds


That's because it is minified. Line by line would also include a lot of spaces and new lines and because of that it would take more file size.

More file size = more traffic and there is your reason.

Minimizing files saves traffic. When you've got a big website, you should do the same to your code.

Here is a nice open source project for you which does it: http://code.google.com/p/minify/

like image 28
Rene Pot Avatar answered Nov 20 '22 14:11

Rene Pot


This is because they want to shorten the library! There are two versions:

Development which is coded as you mentioned

Production which is shorter and has less Size

See Minification

like image 2
Neysor Avatar answered Nov 20 '22 12:11

Neysor


It's minified, to download faster.

You can read the uncompressed code here: http://code.jquery.com/jquery-1.7.1.js

Example:

function add(value1, value2)
{ 
   return value1 + value2;
}

function a(b,c){return b+c;}

Functions add and a perform the same operation and have the same result, but a requires fewer bytes to express and as a result needs less storage space. Downloading the file is consequently faster.

like image 2
Ryan Avatar answered Nov 20 '22 14:11

Ryan