If the minification of CSS-code and JavaScript-code has already become a good tone when creating serious sites, what about PHP-code? Something I have not heard that all PHP-files sought to merge into one and remove all spaces. Probably it doesn't make much sense?

  • 2
    The PHP code does not travel across the network in the form of several requested files and the investigator does not impose additional costs on the network. And the result of its execution is a single HTML code, which, too, can be minimized, although it is possible. - Alex Krass

2 answers 2

We must answer the question "why"

CSS and JS - because this data is transmitted over the network. Perhaps on a slow network of some GPRS. Or, which is often much worse, on an unstable network. Less data transfer means faster loading on the client. When distributing gzip, the effect turns out to be much smaller, but if it’s equal when the static is collected, it is compiled (sass / less, for example, or some other preprocessor), compressed by gzip (so that nginx doesn’t squeeze the static for each request, but select-suitable-stages-for-your-project - then one more step with minifikation is worth adding.

PHP is executed entirely on the server, the source is not transmitted anywhere on the network. What bonus can you want to get after minification? It may be an idea to save a little bit on the time of parsing the source text - but why, if you can not parse the source at all for each request, and re-use the opcode right away? Several additions of opcode caching have been around for a long time, in the already PHP PHP 5.5, opcache transferred to the main PHP code (but it is turned off by default).

That is, it is possible to minify by analogy with JS, but there is no answer to the question "why." Therefore not used.

  • By the way, in ancient times it would have made sense ... more than once met with the requirement "not to use 4 spaces, use tabs" in the codestyle guides, to minimize the load ... did it have a real effect or not - I still did not understand I then believed the older comrades and the saying "there is no smoke without fire." But those times are gone, so yes, the correct answer is "no" :) - AlexandrX
  • Excellent - one less problem! - Bokov Gleb

Not. The code is executed on the server, and not transmitted over the network to the client. And in the minification of css and js in the age of universal gzip is not enough. But it makes sense to merge small files into 1 - so that there are fewer requests.