简体   繁体   中英

Page code compression is really needed?

I don't really love when the code in the page is written in one line, when I wasting a lot of time to try to understand something in there, really the compressed code written in a page worth it? By the principles of programming, code should be readable for others programmers who will come to maintain it too.

and by the way, HTML comments could decrease page load time? because they are visible to others.

<!-- comment goes here -->

but java comments? they is not visible to others

<%-- comment goes here --%>

I think you are confusing many concepts here.

Page compression can be done at various levels. You can employ mod_gzip and mod_deflate or similar modules on your web or web-application servers, to compress the raw bytes served by the web/application server. This often saves a lot of bandwidth and is usually not a cause of problems for web-developers, because the browser will decompress the page content before rendering it (or displaying the source back in the "View Source" context).

The "page written in one line" is not compression. The technical term is minification or obfuscation. It is typically done for JavaScript, to reduce the size of the JavaScript file being served; this can reduce the filesize drastically, with the added benefit of being difficult to parse by human-readers. Web-developers who employ JavaScript minifiers are often clever enough to have the non-minified version of the source code available, so that debugging is not an issue.

One of the former customer sites that I've worked on, demonstrated a performance increase of upto 40% when employing GZIP compression on the wire, and between 5-10% when deployed with minified JavaScript files (there were thousands of such files). But again, your mileage might vary when using these techniques.

Finally, HTML comments ( <!-- comment goes here --> ) do have a performance hit, as it takes more time to serve pages with comments, than pages without them. The impact on rendering might be negligible, as comments are often stripped out by the lexical analyzer. This is not true of JavaScript comments in inline script tags that are first parsed by the HTML parser. The second type of comments ( <%-- comment goes here --> ) is never served by the application server, as it is a JSP-style comment, and the JSP compiler usually ignores these comments, thus not generating any comments in the resulting HTML content.

HTML isn't meant to be read by others when it's being used in production. Generally the original code is going to be readable and things like HTML and JavaScript are commonly minified to decrease load time.

And yes, any comment that your browser has to download is going to increase page load time.

I don't really love when the code in the page is written in one line, when I wasting a lot of time to try to understand something in there, really the compressed code written in a page worth it?

It can be

By the principles of programming, code should be readable for others programmers who will come to maintain it too.

That is why minification is done as part of the build process. Developers working on it get sensibly formatted code.

and by the way, HTML comments could decrease page load time? but java comments? they is not visible to others

If it is delivered to the client, then it takes up some bandwidth. That may or may not be a significant amount of bandwidth depending on the context.

Some do it intentionally to discourage examination of their code, although with some effort it can be well formatted and be readable again. This is a bit like code obfuscation seen in Java.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM