Using aspnet 3.5.
I have some javascript functions in my aspx file.
Why do the javascript comments get passed to the browser? It makes the download file unnecessarily large.
Using aspnet 3.5.
I have some javascript functions in my aspx file.
Why do the javascript comments get passed to the browser? It makes the download file unnecessarily large.
Share Improve this question asked Aug 20, 2009 at 16:40 Lill LanseyLill Lansey 4,91513 gold badges58 silver badges77 bronze badges7 Answers
Reset to default 14Javascript is evaluated on the client, so it downloads all the source (including the comments).
Which is why production environments will typically minify/pack Javascript files. This removes unnecessary white-space and comments.
But if the comments are in the HTML file itself (or the HTML document outputted by an ASP.NET page) then the server has to either send the comments to the client or have an extra step to strip them out. The problem is that this process could be relatively expensive since 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 simple as a regular expression search and replace (not if you want it to be reliable at any rate).
Because asp.net doesnt do any compression/preprocessing of js files before sending it to the client . You need to use something like YUI Compressor to achieve that .
Because you're not doing anyting to remove them. Look into "minifier"s, such as jsmin from Crockford. These strip out comments and unnecessary whitespace. You integrate them into your build process, so your source file is distinct from what actually gets delivered to the browser.
Cause it's client side :)
Why not remove the comments? There are pretty good javascript minifiers available for free
1) compress your javascript before deployment. This is a good thing anyways, because you can get dramatic size reductions even after removing comments
2) if you truly have random bits javascript lying around your aspx file, you could consider using asp server-side comments <%-- --%> instead unlike clientside HTML comments or javascript // comments, these won't get sent over the wire.