diff --git a/base.php b/base.php index e31c847..30eeea4 100644 --- a/base.php +++ b/base.php @@ -35,6 +35,7 @@ if (!file_exists(__DIR__ . '/_env.php')) { define('JS_WEB_ROOT', $root); +define('ESP_PROD', (bool)getenv('ESP_PROD')); define('ESP_DEMO', (bool)getenv('ESP_DEMO')); if (ESP_DEMO) { define('DEMO_APS', << $p) { // making it not a very big improvement at the expense of ugly html. // $s = process_html($s); ob_clean(); - } // clean up - $of = $dest . $_k . ((in_array($_k, $no_tpl_files)||ESP_DEMO) ? '.html' : '.tpl'); - file_put_contents($of, $s); // write to a file + } + + $outputPath = $dest . $_k . ((in_array($_k, $no_tpl_files)||ESP_DEMO) ? '.html' : '.tpl'); + + if (file_exists($outputPath)) unlink($outputPath); + if (ESP_PROD) { + $tmpfile = tempnam('/tmp', 'espterm').'.html'; + file_put_contents($tmpfile, $s); + // using https://github.com/tdewolff/minify + system('minify --html-keep-default-attrvals '. + '-o '.escapeshellarg($outputPath).' '. + ''.escapeshellarg($tmpfile), $rv); + + // fallback if minify is not installed + if (!file_exists($outputPath)) file_put_contents($outputPath, $s); + } else { + file_put_contents($outputPath, $s); + } } ob_flush();