Created
March 18, 2023 15:18
-
-
Save ivanhub/c90e09ab39bd9c8b6dd994521fd9e96c to your computer and use it in GitHub Desktop.
best_html_minifier
This file contains hidden or 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
| <?php | |
| if (!isset($_GET['dev'])) { | |
| $cid = $modx->resource->get('id'); | |
| //$exclude = $modx->getOption('exclude',$scriptProperties,'12'); | |
| if(empty($cid)) { return; } | |
| if(in_array($cid,explode(',',$exclude))) { return; } | |
| $output = &$modx->resource->_output; | |
| //remove all comments | |
| // $output = preg_replace('/' . '(?:\/\*(?:[\s\S]*?)\*\/)|(?:<!--(?:[^\[][\s\S]*?)-->)|(?:([\s])+\/\/(?:.*))' . '/', '', $output); | |
| // $pattern = '/(?:(?:\/\*(?:[^*]|(?:\*+[^*\/]))*\*+\/)|(?:(?<!\:|\\\|\'|\")\/\/.*))/'; | |
| // $output = preg_replace($pattern, '', $output); | |
| $Search = array( | |
| '/\/\/\ .*/', | |
| '/(\n|^)(\x20+|\t)/', | |
| '/(\n|^)\/\/(.*?)(\n|$)/', | |
| '/\n/', | |
| '/\<\!--.*?-->/', #same выше | |
| '/(\x20+|\t)/', # Delete multispace (Without \n) | |
| '/\>\s+\</', # strip whitespaces between tags | |
| '/(\"|\')\s+\>/', # strip whitespaces between quotation ("') and end tags | |
| '/=\s+(\"|\')/', | |
| '/ (\t| )+/', # strip whitespaces between = "' | |
| ); | |
| $Replace = array( | |
| "", | |
| "\n", | |
| "\n", | |
| " ", | |
| "", | |
| " ", | |
| "><", | |
| "$1>", | |
| "=$1", | |
| "" | |
| ); | |
| $output = preg_replace($Search,$Replace,$output); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment