Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Bing obfuscate their JavaScript?

I was surfing the web, as usual and I wanted to take a look at Bing's source code because I was curious and wanted to know what they were using to make their image fade in. I was surprised by what could only be qualified by the following line :

Holy wall of text!

And it made me wonder if there is any advantage to obfuscate your (X)HTML, CSS and JavaScript like this? To reduce the size of the file perhaps?


Edit : After looking around, I realized this was a pretty common practice. Never looked at it from a minification point of view before!

like image 540
Gab Royer Avatar asked Jul 01 '09 18:07

Gab Royer


4 Answers

They are not obfuscating. They are minifying in order to reduce the bandwidth used by the millions of requests they see each day.

The goal of JavaScript and CSS minification is always to preserve the operational qualities of the code while reducing its overall byte footprint (both in raw terms and after gzipping, as most JavaScript and CSS served from production web servers is gzipped as part of the HTTP protocol).

You might also be interested in reading the Yahoo! User Interface blog post titled "Minification v. Obfuscation".

like image 109
William Brendel Avatar answered Oct 06 '22 08:10

William Brendel


2 main reasons to obfuscate your code:

  • Reduce the total size of the file (like you mentioned) If you replace a function called 'CallThisFunctionAndReturnAnArray' with 'C' - you've saved a lot of characters in your file.

  • Protect intellectual property - while if this is realistic is definite debatable, this is common justification for doing so. You can get around this with good tools, or if you are just really smart.

like image 23
Adam Avatar answered Oct 06 '22 10:10

Adam


File size would certain be a benefit, so much that for example Gmail itself not only does that but also zip its contents.

like image 28
Otávio Décio Avatar answered Oct 06 '22 10:10

Otávio Décio


There is absolutely an advantage to this. There is something important to note, though. There is no reason to actually code like this. Rather, after you are finished doing something (and writing in good readable form), use a minifier to remove unneeded white-space and such. For larger files this can greatly decrease load times.

like image 45
Peter Avatar answered Oct 06 '22 10:10

Peter