Why are javascript comments loaded into the browser?

Using aspnet 3.5.

I have some javascript functions in my aspx file.

Why are javascript comments being passed to the browser? This makes the download file unnecessarily large.

+2


source to share


7 replies


This is why production environments usually minify / package Javascript files. This removes unnecessary spaces and comments.



But if the comments are in the HTML file itself (or in the HTML document rendered to the ASP.NET page), the server must either send the comments to the client or take an extra step to remove them. The problem is that this process can be relatively expensive as you basically have to parse the HTML output to figure out where the Javascript is and then where the comments are. It's not as easy as finding and replacing a regex (not if you want it to be reliable anyway).

+8


source


Javascript is evaluated on the client, so it loads the entire source (including comments).



+14


source


As asp.net does not compress / preprocess js files before sending it to client. You need to use something like YUI Compressor for this .

+4


source


Because you make no attempt to remove them. Take a look at a "minifier" like jsmin from Crockford. They highlight comments and unnecessary spaces. You integrate them into your build process, so the source file is different from what is actually delivered to the browser.

+3


source


Because this is the client side :)

+2


source


Why not remove comments? There are some nice javascript minifiers available for free

+2


source


1) compress javascript before deploying. This is good anyway, because you can get a sharp reduction in size even after removing comments.

2) if you do have some random bits of javascript lying around your aspx file, you might consider using server side asp <% - -%> comments instead, as opposed to HTML client comments or javascript comments //, t sent by wire.

+1


source







All Articles