10
If I want to minify an HTML page from PHP I will be more winning or losing?
More clearly: I want to keep the formatting and practicality for when editing the page, preserving the edentation. But I also worry about page loading, since in the development it is becoming heavier than I would like, so a solution is to minify and save some Kbs by removing all that is unnecessary for the user to download the page. Similarly with CSS and JS.
But since I wanted to do this with PHP (generate an output by removing the waste), I wondered if I would spend more time processing the page than if it had not minified and the download was made.
I understand that this depends on several factors, but I would like to consider large volumes of information (about 2MB non-minified and 1.2MB minified), which is almost 60% difference in size. What are the factors that would slow down the processing of the page?
There are other options to make the page light?
Really, just measuring the performance of your specific case to know, but minify on-the-fly at each request does not seem a good idea in general terms. You have come to consider the option to save minified pages in cache for a period?
– bfavaretto
I do not know if 'chachear' the pages is a good idea, it is updated with a certain daily frequency in a fickle way and I imagine that it would generate problems in this specific case.
– Gabriel Tadra Mainginski
It is worth "minify" the HTML if you want to save the maximum in bandwidth. The processing is fast and is very good mainly for slow connections. In PHP, it is easy, just use a combination of
ob_start
to get the original HTML +str_replace
to eliminate spaces and line breaks +preg_replace
to delete comments. If you do not use CSRF tokens or redirects, you can cache the HTML on the server. But there are some priorities before that, like Gzip, HTTP cache, optimizing images, combining JS and CSS, using CSS sprites, using a CDN if possible, etc– user622
I edited my answer clarifying your doubt
– Ricardo