Poor looking final source code

Permalink
on all my sites the final html code, c5 generates, is correct but very unbeautiful. There are up to 25 lines empty space. That looks very poor.

All my templates are free of empty lines. Why does C5 do that, and is there a solution to this problem?

Thanks in advance.

MathiasB
 
Steevb replied on at Permalink Reply
Steevb
Do you have a URL we can look at?
MathiasB replied on at Permalink Reply
MathiasB
Yes of course I have:
http://www.brahms-institut.de (from line 138)
Steevb replied on at Permalink Reply
Steevb
Spacing in code is probably in block view.php, look at the views and clean up the spacing.

Doctype is ‘XHTML 1.0 Transitional’, should be HTML5 and lang should be ‘de’.

<!DOCTYPE html>
<html lang=“de”>


Mixed closing tags (>) and (/>), use HTML5 and close tags with (>)

Forget script in header for IE8, not really needed anymore.

Too many style sheets.

Javascript under opening ’body’ tag, not good, should be in footer.

Script type in footer is showing error with 'attribute' missing, change doctype to HTML5 and the error will be fixed. Same with the 'footer' element.

Flex item code is wrong.
Flex wrap id should be either unique or change to a class.
<div id="pl_flex">


Remove ‘index.php’, enable pretty URL’s.

Closing tag could be missing for page template.
<div class="ccm-page page-type-standard page-template-full”>


Try using ‘Total Validator’ to help with clearing errors: https://www.totalvalidator.com/...

Hope that helps gives you a start on how to fix errors.
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
Whilst steevb has summarised the issues and what can be done in detail, the chances are this is mostly arising from the site theme combined with a few addons.

To combine css and js switch on the css and js combine/minify cache in the dashboard. If that doesn't help, it is likely the theme or addons are not making assets cacheable.

You will need to edit the theme anyway to fix many of the detailed issues steevb has identified.

For generally nice layout of source code, indentation, line spacing etc, you could tryhttps://www.concrete5.org/marketplace/addons/html-beautifier....

In practice, most sites want to compress html rather than beautify it. The same addon will strip all excess white space and reduce it to a minimum.

Being more realistic, making the html conform to standards is more relevant than making it look pretty or compressing it. Visitors don't care how pretty html is. They only care how pretty the rendered page looks. But standards conformity affects how easily browsers can render a site and avoids ambiguities where different browsers make a slightly different 'best guess' interpretation - which is again back to fixing the theme points steevb identifies.
MathiasB replied on at Permalink Reply
MathiasB
You are right. It was the code of my theme. I didn't know, that PHP is generating an empty line in the HTML-code, if there is an empty line in the PHP-code.

I use several "if" commands to create different layouts for different page-types and I divided them with a single empty line in order to a better overview. PHP obviously generates a further empty line in HTML, when an "if" is false. In case of five false "ifs" there are ten empty lines in HTML.

ANYWAY. SOLVED. THANKS! :-)
MathiasB replied on at Permalink Reply
MathiasB
Thanks a lot for your tips. I really should supervise my themes and all my block templates. I am not a specialist. For that reason, I do these mistakes.

But the problem was a couple of single(!) empty lines in my PHP. I deleted them, and now the code looks much better.