Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php source code whitespace

Tags:

php

I am familiar with the concept of minification in Javascript and how whitespaces contribute to JS file sizes, but does that concept not apply to PHP scripts?

does whitespace make php scripts file sizes larger? can we minify php scripts? or is there no point in doing so because whitespaces in source codes in php does not affect anything at all?

like image 486
yretuta Avatar asked Nov 17 '09 08:11

yretuta


2 Answers

There's no point in doing so because users don't download your PHP file. There's no need to minify server-side scripts.

like image 121
danielkza Avatar answered Sep 22 '22 17:09

danielkza


There is a small gain in speed, if you have optimized whitespace in PHP files (reading in and compiling the file), but it is, compared to the rest, insignificant (that said, you can gain more rewriting all unnecessary 'preg_replace' with the appropriate string methods).

Actually, there are possibilities to precompile a PHP file and present this optimized code to the PHP interpreter. Search for Zend Encoder or IonCube. But then, the source file is no more human-readable.

For JS files the gain in speed stems almost to 100% from the smaller loading time via HTTP.

like image 45
Boldewyn Avatar answered Sep 22 '22 17:09

Boldewyn