Does commented out html or css code in the templates has any effect on the page loading time? Or is it better for me to delete it away, as I do not need them anymore.
The short answer is yes.
It does because it will add to the overall size of the document and affect the download time for the html or css file.
That being said, if you have a few lines commented out it's not a big deal. If you have a few hundred lines of comments then you may see a slight change in load time.
If you don't need the comments or if it is production code, get rid of them. However, if it is dev code or there may be a future need to re-enable the block, a small amount of commented lines will not be enough to make a difference.
Yes it does affect loading time. But you shouldn't care about it anyway. Let's think about this logically.
Loading time is affected mainly by two things - time it takes for the information to stream from the server to us, and the time it takes for the browser to parse that information and display it on the page. Let's take them separately.
Having a comment will increase file size, so it will increase time for the file to stream to you - thus a comment will increase load time.
Having a comment will increase parsing time, because when the parser encounters the start of a comment, it has to go through (much quicker than usual I presume) the code to find the end of the comment, be it a newline character or something else.
However, these effects are negligibly negligible. Furthermore, comments on live sites should not be snippets/chunks of code you might use in the future, you should save those as backup files. Comments are here for readability of the developer.
HTML and CSS comments are still counted towards the size of the files that they are in. The bigger the file, the longer it will take to download.
It's good practice to remove any unused code and minimize your css/js files when you're deploying to production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With