If the minification is well done, usually by a trusted (reputable) software or script then there will be no problems with the HTML interpreter even in older browsers, the only thing you might should avoid is to make the entire html inline , like this:
<html><heade></head><body></body></html>
Even though you can hardly read the source in production, there may still be a need in the future to analyze mainly pages whose content is dynamic, but if you have a good organization of the development environment, you can compress < in> inline
The PHP part (codes between <?php
and ?>
) is totally unnecessary to minify, as does not accelerate almost anything page delivery and interpreter processing, on the contrary you can have multiple headaches, for example there are many people who write if
without {...}
when it only has one line later (the problem may only occur in some versions of PHP), even if the PHP script has a million PHP-only minify lines will not speed up processing it, it might even bother the PHP interpreter.
However, there is a native PHP function that calls php_strip_whitespace
that removes spaces blank and line breaks, as quoted by @WallaceMaxters, it can be used like this:
<?php
echo php_strip_whitespace('outro-arquivo.php');
But remember you should not use running, it will not bring any benefit, the interesting thing is to use template systems that create page caches for example.
If you have html + php, like this:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div>
...300 linhas de HTML
</div>
<div>
<?php
//1000 linhas de PHP
?>
</div>
<div>
<?php
//1000 linhas de PHP
?>
</div>
<div>
<?php
//1000 linhas de PHP
?>
</div>
<div>
...1000 linhas de HTML
</div>
</body>
</html>
Just pays to compress the HTML, PHP does not compensate as I mentioned, what you can try to make easier is to use frameworks that support Views, such as Laravel and Cakephp, so you will separate the HTML inside the Views and most of logic will stay in Controller and Model, or you can also use
include
for compressed HTML parts like this:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div>
<?php include 'arquivo-com-300-linhas-de-html-comprimidas-em-uma.php'; ?>
</div>
<div>
<?php
//1000 linhas de PHP
?>
</div>
<div>
<?php
//1000 linhas de PHP
?>
</div>
<div>
<?php
//1000 linhas de PHP
?>
</div>
<div>
<?php include 'arquivo-com-1000-linhas-de-html-comprimidas-em-uma.php'; ?>
</div>
</body>
</html>
As for PHP comments, it does not pay to remove them since it will not make much difference in performance, since the HTML ones if they are too long or too long is better to remove.
Tools to compress HTML:
You may also want to minify files like CSS and JS:
Accelerating PHP
A detail worth mentioning is that PHP is an interpreted language, I mean at each request the PHP files will be reprocessed before they are executed, the language itself does not have natively JIT (Just in time), however from PHP5.5 we have Opcache
(you must enable it), in older versions you must install manually or via PEAR or even compile manually (most likely on Linux servers).
Extensions such as Opcache
and Xcache
greatly improve the performance of websites in PHP, as it will not be necessary to interpret the scripts for each request, more details in: