Are places / comments slowing down Javascript?

I was wondering if spaces and comments slow down JavaScript? I am doing a brute force attack that takes some time (30 seconds). Removing spaces does not show a significant increase in speed, but I think the browser just has to figure it out more.

So, is it possible to use extra spaces and comments to speed things up?

+6
javascript
source share
5 answers

People usually use minimizers to reduce the size of the script, to improve download speed, and not to make a difference in the speed of parsing the script.

Spaces and comments will have little effect on browser runtime, since the parser needs to check whether this is a space or comment, but in fact it will be so small with the current processing power, it is impossible to notice any effect.

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

+10
source share

Spaces and comments increase the size of the JavaScript file, which slows down the actual download of the file from the server - minimization is the process of removing unnecessary characters from the JavaScript file to make it more compact and easy to download.

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

+3
source share

There is always a point in minimizing, combining and gzipping your assets to facilitate server loading.

  • Minification is the action you refer to, removing unnecessary spaces and comments to reduce download speed.
  • The combination is likely to show an even greater increase in page rendering speed; this is the act of combining all your javascript files into one and all your css files into one (this can also be done for most images, but this requires another work). This is done to reduce the number of requests that the browser must make on your server in order to display the page.
  • GZipping is the action of further compressing the compressed data in browsers that indicate that they will accept such data. This further reduces size, but adds some extra workload from both ends. You are likely to see a net profit from it.

Depending on the environment in which you work, there are different components that will help you with this, which usually covers all of the above at a time.

The time that your code takes to load from the server directly affects the time the page takes to render. JavaScript blocks, which means the JS block will prevent any visualization of the future until the block completes. Thus, when you place javascript files (i.e., at what point in the rendering process they will be requested), how many requests that are required to fully load it, and how much data to load, will have an effect on the download page, as it appears to the user.

As soon as the browser analyzes your code, whether it be javascript, css or html, it will create internal representations of the part that it needs to remember, and the actual formatting will no longer affect it.

+3
source share

I do not think that a space in the js code slows down its execution. As I understand it, the javascript interpreter breaks all comments and redundant spaces before processing. This can affect the loading time and thus the loading time of the web page.

Look here for more information.

+1
source share

This has little effect on the actual processing speed, however ...

Smaller size => less bandwith => less cost => ??? => profit!

0
source share

All Articles