Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do spaces/comments slow Javascript down?

Tags:

javascript

I was wondering, do whitespaces and comments slow down JavaScript? I'm doing a brute force attack which takes some time (30 seconds). Removing whitespaces does not show a significant growth in speed, but I think the browser just does have to parse more.

So, is it of any use to remove unnecessary whitespaces and comments to speed the whole up?

like image 751
pimvdb Avatar asked Dec 12 '10 19:12

pimvdb


2 Answers

People usually use minimizers to reduce the SIZE of the script, to improve download speed, rather than to make any difference in speed of parsing the script.

Whitespace and comments will have little effect in how long it takes a browser to execute, as the parser needs to check if it is whitespace, or a comment, but in reality this will be so minute with current computing power, it would be impossible to notice any impact.

SIZE however is still important even with the large bandwidth available in our broadband world.

like image 58
Codemwnci Avatar answered Sep 21 '22 01:09

Codemwnci


Whitespaces and comments increase the size of the JavaScript file, which slows down the actual downloading of the file from the server - minification is the process of stripping unnecessary characters from a JavaScript file to make it smaller and easier to download.

However, since you mention a brute force attack, the bottleneck is probably not the download. Try using a profiler to find what slows you down.

like image 27
Victor Nicollet Avatar answered Sep 23 '22 01:09

Victor Nicollet