Well for compression, I think it's mostly because eventually someone has to read or maintain it. Especially for CSS codes, so it's more about striking a balance. You only save on the newline characters anyway, so like in the first example.
1 2
|
body { background-color: #fff; font-family: Arial; margin: 0 auto; }
#container { position: relative; margin: 0 auto; width: 960px; padding: 20px; }
|
We only have 2 newline characters, whereas on the second example
1 2 3 4 5 6 7 8 9 10 11 12
|
body {
background-color : #fff;
font-family : Arial;
margin : 0 auto;
}
#container {
position: relative;
margin: 0 auto;
width: 960px;
padding: 20px;
}
|
We have 12 newlines characters.
The first example isn't that much harder to read though cause we know the selector is on the left side, so it's easy to find the styles for the body, and it's also quite easy to find the style for the html element with an id of "container". So you get something that's not so difficult to maintain, yet not bloated. Having that balance is usually good in my opinion, cause then you'd somewhat have the best of both worlds.
That probably doesn't work well with javascript though cause I don't think it would help with readability anyway. So compressed javascript code would most likely be all placed on a single line in my opinion.
As for obfuscation, I don't really see any reason not to put obfuscated code all in a single line either.
Edit:
Oh lolz, I just looked up this site's css and javascript file and both have their code on a single line for maximum compression. I think even spaces have been removed.
http://www.cplusplus.com/main29g.css
http://www.cplusplus.com/main29f.js
I think most of the time the purpose is for compression though instead of obfuscation. You can easily tell if it's not obfuscation when the code has descriptive variables and function names I mean.