html minification

box-drawing
Ondřej Hruška 7 years ago
parent ba24c4f967
commit 57a295b544
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 1
      base.php
  2. 21
      compile_html.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', <<<APS

@ -55,9 +55,24 @@ foreach($_pages as $_k => $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();

Loading…
Cancel
Save