Last active
June 2, 2018 23:40
-
-
Save iksi/5866974c800c01ff2bdc to your computer and use it in GitHub Desktop.
Minify Kirby’s HTML output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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