Question

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!

Was it helpful?

Solution

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".

OTHER TIPS

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.

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

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.

I will answer that "obfuscation" is not the goal in these cases, but bandwidth. If you are serving cacheable content at such a rate that reducing the homepage size would be beneficial, then it does make sense to do so.

As for obfuscation to steer away prying eyes - No. Don't do that.

Only to reduce size, and only on large modules. A much greater gain can be achieved using gzip.

If you use any third party code, you may be required to leave their copyright/license comments intact when you minify. People often forget to do this. You'll probably want to leave your own copyright comments intact too.

Yes, file size reduction.

Yes. Reducing file size not only decreases the download time but also the parse time, which is very useful on some browsers (particularly the devil-spawned IE6).

This probably wants retagging minification.

I would draw a difference between optimization to reduce file size and obfuscation with the intended purpose of preventing (or at least making hard) reverse engineering. Also, google for example has a "compiler" that extends JavaScript to include some advanced type system and the like; and this extended code is then "compiled" into regular JavaScript. Obviously it makes sense to create this generated code in an optimized manner -- there's no need to make it maintainable.

I would bet the main reason they do this is to reduce the file size. Smaller files makes the page load faster.

Obfuscating is not as important. Also, it can make things a pain to debug, depending on how you do it.

Speed is everything in search.

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?

Obfuscation is slightly different from another common technique with Javascript files, minification. Minification is common with Javascript since it reduces the file size, which, with large files can significantly reduce their size (since large Javascript files often contain lots of comments, line breaks, unneeded spaces and so forth which can be stripped to reduce the size of the script).

Obfuscation, on the other hand, is also more about concealing your code from others, by changing variable names to others which are obscure, or that remove meaning from the Javascript files. However, by doing this it often reduces the file size, since variable names are often much shorter than those in the original file. This is a common technique to make it harder for others to simply copy code, and is more about protecting the code which is obviously much more easily accessible compared to other platforms.

Doing both minification and obfuscation are advantageous to your scripts, since they reduce the size of your Javascript files, which reduces the time taken to load your pages, and also makes it harder for others to reverse engineer it (if this is an issue for your code).

However: note that it's not foolproof - there are certain tools that exist which make it easier to reverse engineer obfuscated code, so it doesn't make it 100% safe from others who really want to take a look at how your scripts work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top