Skip to content

Instantly share code, notes, and snippets.

@iksi
Last active June 2, 2018 23:40
Show Gist options
  • Save iksi/5866974c800c01ff2bdc to your computer and use it in GitHub Desktop.
Save iksi/5866974c800c01ff2bdc to your computer and use it in GitHub Desktop.
Minify Kirby’s HTML output
/**
* Uses Alan Moore's regexp:
* http://stackoverflow.com/questions/5312349/minifying-final-html-output-using-regular-expressions-with-codeigniter
*
* Replace `echo $kirby->launch();` in Kirby’s index.php by
* the following code to minify the HTML output
* (it leaves whitespace within `<pre>` and `<textarea>` tags untouched)
*/
echo preg_replace(
'/(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!\/?(?:textarea|pre)\b))*+)
(?:<(?>textarea|pre)\b|\z))/ix', '', $kirby->launch()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment