Tom
Tom

Reputation: 199

Why/how do programmers remove spaces?

I hope this doesn't sound silly, but I've noticed a lot of Javascript files used on websites have no spacing or notes.
Normally just one extremely long string of code.
Why is that?
Does the programmer make it that way after writing it, or is that just the way its rendered afterwards?

Upvotes: 1

Views: 113

Answers (4)

DevelopmentIsMyPassion
DevelopmentIsMyPassion

Reputation: 3591

Its concept of compressing the pages. Its called minifying. What it does is remove all the spaces in the script files. There are lot of tools to minify the js files. This improves performance of web pages. You can google on javascript minification. Hope its clear to you.

Upvotes: 0

Joachim Isaksson
Joachim Isaksson

Reputation: 180887

What you're referring to is called minification and is usually done to minimize the space required to transfer and cache the Javascript.

Reading the linked Wikipedia article and Googling that term will find you many alternative online and offline applications that can help you achieve that.

Minification isn't limited to Javascript, but can also be used on - for example - CSS with very good results.

Upvotes: 6

Bob van Luijt
Bob van Luijt

Reputation: 7588

The reason for this is file size. The smaller the file, the faster a webpage gets loaded. Sometime these compressed files are 50% of the original(!)

Upvotes: 0

Ted Hopp
Ted Hopp

Reputation: 234795

After writing your code in a sane way, it's common to run JavaScript through a minifier to reduce download time and bandwidth. (It also provides a false sense of security because your code has been mildly obfuscated.) Many JS development tools packages come with built-in a minifier and minifiers are available on-line.

Upvotes: 1

Related Questions