Gowri
Gowri

Reputation: 16845

Does commented html causes page loading time

Does commented html elements and White spaces will causes page loading time.I know commented markup will not run by browser.compressing markup is the good idea while deploying in server

<!--Html Elements --> 

Upvotes: 0

Views: 2386

Answers (3)

user542603
user542603

Reputation:

Your page size will be increased but the execution time will stay the same as the comments are not parsed.

If you are using a server-side language, you can use their comments instead, like so:

<ul>
    <li>Something</li>
    <?php /* <li>Else</li> */ ?>
</ul>

This will hide the HTML from anyone poking around in your source code and will reduce the page size as the commented out HTML will not be sent to the user.

You could also use PHP's output control functions to automatically strip out any HTML comments. More info here: http://www.php.net/manual/en/ref.outcontrol.php

You can also use those functions to compress your pages, remove whitespace, etc, which will also speed up page load by decreasing page size.

Upvotes: 0

Xavi L&#243;pez
Xavi L&#243;pez

Reputation: 27880

It won't be run by the browser, but it will be in every case streamed by the server, and downloaded by the client. It shouldn't make any difference, as long as you don't have enourmous amounts of characters in there.

If you're using dynamic pages generated server side, you might be interested in server-side comments, that don't get streamed in the response, so the client never downloads/sees them.For instance, in JSP, <%-- this is a server-side comment --%>.

Also, remember that javascript code is not affected by these comments, actually, <!-- --> is used to to avoid javascript code showing up on old old browsers that didn't support javascript. See this link: Hiding JS code from old browsers.

Upvotes: 1

thorne51
thorne51

Reputation: 618

It will still increase your page size, but shouldn't be a problem. Having 10000 lines of commented-out HTML is going to be a problem though, but keeping your comments small, should not increase the page size by too much.

Upvotes: 2

Related Questions