-
-
Save Alliline/fc5e9827cefea447bb74390b7108c6b9 to your computer and use it in GitHub Desktop.
Revisions
-
Rodrigo54 revised this gist
May 31, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -72,7 +72,7 @@ function minify_css($input) { // Remove comment(s) '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s', // Remove unused white-space(s) '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', // Replace `:0 0 0 0` with `:0` -
Rodrigo54 revised this gist
Feb 6, 2016 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -19,6 +19,17 @@ function minify_html($input) { return '<' . $matches[1] . ' style=' . $matches[2] . minify_css($matches[3]) . $matches[2]; }, $input); } if(strpos($input, '</style>') !== false) { $input = preg_replace_callback('#<style(.*?)>(.*?)</style>#is', function($matches) { return '<style' . $matches[1] .'>'. minify_css($matches[2]) . '</style>'; }, $input); } if(strpos($input, '</script>') !== false) { $input = preg_replace_callback('#<script(.*?)>(.*?)</script>#is', function($matches) { return '<script' . $matches[1] .'>'. minify_js($matches[2]) . '</script>'; }, $input); } return preg_replace( array( // t = text -
taufik-nurrohman revised this gist
Nov 22, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ function minify_html($input) { '#( ) (?![<\s])#', // clean up ... '#(?<=\>)( )(?=\<)#', // --ibid // Remove HTML comment(s) except IE comment(s) '#\s*<!--(?!\[if\s).*?-->\s*|(?<!\>)\n+(?=\<[^!])#s' ), array( '<$1$2</$1>', -
taufik-nurrohman revised this gist
Nov 21, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ function minify_html($input) { '#( ) (?![<\s])#', // clean up ... '#(?<=\>)( )(?=\<)#', // --ibid // Remove HTML comment(s) except IE comment(s) '#\s*<!--(?!\[if\s).*?-->\s*|(?<!\>)\n+(?=\<[^\/!])#s' ), array( '<$1$2</$1>', -
taufik-nurrohman revised this gist
Nov 21, 2015 . 1 changed file with 48 additions and 83 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,101 +9,75 @@ // HTML Minifier function minify_html($input) { if(trim($input) === "") return $input; // Remove extra white-space(s) between HTML attribute(s) $input = preg_replace_callback('#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#s', function($matches) { return '<' . $matches[1] . preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]) . $matches[3] . '>'; }, str_replace("\r", "", $input)); // Minify inline CSS declaration(s) if(strpos($input, ' style=') !== false) { $input = preg_replace_callback('#<([^<]+?)\s+style=([\'"])(.*?)\2(?=[\/\s>])#s', function($matches) { return '<' . $matches[1] . ' style=' . $matches[2] . minify_css($matches[3]) . $matches[2]; }, $input); } return preg_replace( array( // t = text // o = tag open // c = tag close // Keep important white-space(s) after self-closing HTML tag(s) '#<(img|input)(>| .*?>)#s', // Remove a line break and two or more white-space(s) between tag(s) '#(<!--.*?-->)|(>)(?:\n*|\s{2,})(<)|^\s*|\s*$#s', '#(<!--.*?-->)|(?<!\>)\s+(<\/.*?>)|(<[^\/]*?>)\s+(?!\<)#s', // t+c || o+t '#(<!--.*?-->)|(<[^\/]*?>)\s+(<[^\/]*?>)|(<\/.*?>)\s+(<\/.*?>)#s', // o+o || c+c '#(<!--.*?-->)|(<\/.*?>)\s+(\s)(?!\<)|(?<!\>)\s+(\s)(<[^\/]*?\/?>)|(<[^\/]*?\/?>)\s+(\s)(?!\<)#s', // c+t || t+o || o+t -- separated by long white-space(s) '#(<!--.*?-->)|(<[^\/]*?>)\s+(<\/.*?>)#s', // empty tag '#<(img|input)(>| .*?>)<\/\1>#s', // reset previous fix '#( ) (?![<\s])#', // clean up ... '#(?<=\>)( )(?=\<)#', // --ibid // Remove HTML comment(s) except IE comment(s) '#\s*<!--(?!\[if\s).*?-->\s*|(?<!\>)\n+(?=\<)#s' ), array( '<$1$2</$1>', '$1$2$3', '$1$2$3', '$1$2$3$4$5', '$1$2$3$4$5$6$7', '$1$2$3', '<$1$2', '$1 ', '$1', "" ), $input); } // CSS Minifier => http://ideone.com/Q5USEF + improvement(s) function minify_css($input) { if(trim($input) === "") return $input; return preg_replace( array( // Remove comment(s) '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s', // Remove unused white-space(s) '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', // Replace `:0 0 0 0` with `:0` '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i', // Replace `background-position:0` with `background-position:0 0` '#(background-position):0(?=[;\}])#si', // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space '#(?<=[\s:,\-])0+\.(\d+)#s', // Minify string value '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', // Minify HEX color code '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', // Replace `(border|outline):none` with `(border|outline):0` '#(?<=[\{;])(border|outline):none(?=[;\}\!])#', // Remove empty selector(s) '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s' ), array( @@ -116,43 +90,34 @@ function minify_css($input) { '$1$3', '$1$2$4$5', '$1$2$3', '$1:0', '$1$2' ), $input); } // JavaScript Minifier function minify_js($input) { if(trim($input) === "") return $input; return preg_replace( array( // Remove comment(s) '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', // Remove white-space(s) outside the string and regex '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', // Remove the last semicolon '#;+\}#', // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', // --ibid. From `foo['bar']` to `foo.bar` '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' ), array( '$1', '$1$2', '}', '$1$3', '$1.$3' ), $input); } -
taufik-nurrohman revised this gist
Apr 13, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ function minify_html($input) { }, $input); // Minify inline CSS declarations if(strpos($input, ' style=') !== false) { $input = preg_replace_callback('#\s+style=([\'"]?)(.*?)\1(?=[\/\s>])#s', function($matches) { return ' style=' . $matches[1] . minify_css($matches[2]) . $matches[1]; }, $input); } -
taufik-nurrohman revised this gist
Apr 13, 2015 . 1 changed file with 8 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -42,12 +42,10 @@ function minify_html($input) { // If `<tag> abc` remove white-space // If `abc </tag>` remove white-space // If `</tag> abc` keep white-space // TODO: If `abc ...<tag>` keep one white-space // If `<tag> ...abc` remove white-spaces // If `abc ...</tag>` remove white-spaces // TODO: If `</tag> ...abc` keep one white-space '#(<\!--.*?-->)|(<(?:img|input)(?:\/?>|\s[^<>]*?\/?>))\s+(?!\<\/)#s', // o+t | o+o '#(<\!--.*?-->)|(<[^\/\s<>]+(?:>|\s[^<>]*?>))\s+(?=\<[^\/])#s', // o+o '#(<\!--.*?-->)|(<\/[^\/\s<>]+?>)\s+(?=\<\/)#s', // c+c @@ -60,7 +58,7 @@ function minify_html($input) { // Replace ` ` with ` ` '#(?<= )( ){2}#', // Proofing ... '#(?<=\>) (?!\s| |<\/)#', '#(?<=--\>)(?:\s| )+(?=\<)#' ), array( @@ -93,11 +91,11 @@ function minify_css($input) { // Remove unused white-spaces '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` '#(?<=[:\s])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', // Replace `:0 0 0 0` with `:0` '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i', // Replace `background-position:0` with `background-position:0 0` '#(background-position):0(?=[;\}])#si', // Replace `0.6` with `.6`, but only when preceded by `:`, `-`, `,` or a white-space '#(?<=[:\-,\s])0+\.(\d+)#s', // Minify string value @@ -106,14 +104,14 @@ function minify_css($input) { // Minify HEX color code '#(?<=[:\-,\s]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', // Remove empty selectors '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s' ), array( '$1', '$1$2$3$4$5$6$7', '$1', ':0', '$1:0 0', '.$1', '$1$3', '$1$2$4$5', -
taufik-nurrohman revised this gist
Apr 11, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -58,7 +58,7 @@ function minify_html($input) { '#(<\!--.*?-->)|(<\/[^\/\s<>]+?>)\s+(?!\<)#s', // c+t '#(<\!--.*?-->)|(\/>)\s+(?!\<)#', // o+t // Replace ` ` with ` ` '#(?<= )( ){2}#', // Proofing ... '#(?<=\>) (?!\s| )#', '#(?<=--\>)(?:\s| )+(?=\<)#' -
taufik-nurrohman revised this gist
Apr 11, 2015 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -15,7 +15,7 @@ function minify_html($input) { }, $input); // Minify inline CSS declarations if(strpos($input, ' style=') !== false) { $input = preg_replace_callback('#\s+style=([\'"]?)(.*?)\1#s', function($matches) { return ' style=' . $matches[1] . minify_css($matches[2]) . $matches[1]; }, $input); } @@ -104,7 +104,7 @@ function minify_css($input) { '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', // Minify HEX color code '#(?<=[:\-,\s]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', // Remove empty selectors '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#si' ), @@ -131,9 +131,9 @@ function minify_js($input) { // '#(?<!\\\)\\\\\"#', // '#(?<!\\\)\\\\\'#', // Remove comments '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*\s*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*[\n\r]*#', // Remove unused white-space characters outside the string and regex '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\.,;]|[gimuy]))|\s*([+\-\=\/%\(\)\{\}\[\]<>\|&\?\!\:;\.,])\s*#s', // Remove the last semicolon '#;+\}#', // Replace `true` with `!0` -
taufik-nurrohman revised this gist
Apr 11, 2015 . 1 changed file with 19 additions and 10 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,18 +10,24 @@ function minify_html($input) { if(trim($input) === "") return $input; // Remove extra white-spaces between HTML attributes $input = preg_replace_callback('#<([^\/\s<>!]+)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#s', function($matches) { return '<' . $matches[1] . preg_replace('#([^\s=]+)(\=([\'"]?)(.*?)\3)?(\s+|$)#s', ' $1$2', $matches[2]) . $matches[3] . '>'; }, $input); // Minify inline CSS declarations if(strpos($input, ' style=') !== false) { $input = preg_replace_callback('#\s+style=([\'"]?)(.*?)\1#', function($matches) { return ' style=' . $matches[1] . minify_css($matches[2]) . $matches[1]; }, $input); } return preg_replace( array( // Remove HTML comments except IE comments '#\s*(<\!--(?=\[if).*?-->)\s*|\s*<\!--.*?-->\s*#s', // Do not remove white-space after image and // input tag that is followed by a tag open '#(<(?:img|input)(?:\/?>|\s[^<>]*?\/?>))\s+(?=\<[^\/])#s', // Remove two or more white-spaces between tags '#(<\!--.*?-->)|(>)\s{2,}|\s{2,}(<)|(>)\s{2,}(<)#s', // Proofing ... // o: tag open, c: tag close, t: text // If `<tag> </tag>` remove white-space @@ -42,11 +48,11 @@ function minify_html($input) { // If `</tag> ...abc` keep one white-space // If `abc ...<tag>` keep one white-space // If `abc ...</tag>` remove white-spaces '#(<\!--.*?-->)|(<(?:img|input)(?:\/?>|\s[^<>]*?\/?>))\s+(?!\<\/)#s', // o+t | o+o '#(<\!--.*?-->)|(<[^\/\s<>]+(?:>|\s[^<>]*?>))\s+(?=\<[^\/])#s', // o+o '#(<\!--.*?-->)|(<\/[^\/\s<>]+?>)\s+(?=\<\/)#s', // c+c '#(<\!--.*?-->)|(<([^\/\s<>]+)(?:>|\s[^<>]*?>))\s+(<\/\3>)#s', // o+c '#(<\!--.*?-->)|(<[^\/\s<>]+(?:>|\s[^<>]*?>))\s+(?!\<)#s', // o+t '#(<\!--.*?-->)|(?!\>)\s+(<\/[^\/\s<>]+?>)#s', // t+c '#(<\!--.*?-->)|(?!\>)\s+(?=\<[^\/])#s', // t+o '#(<\!--.*?-->)|(<\/[^\/\s<>]+?>)\s+(?!\<)#s', // c+t @@ -97,6 +103,8 @@ function minify_css($input) { // Minify string value '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', // Minify HEX color code '#(?<=[:\-,\s]\#)([a-z0-6]+)\1([a-z0-6]+)\2([a-z0-6]+)\3#i', // Remove empty selectors '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#si' ), @@ -109,6 +117,7 @@ function minify_css($input) { '.$1', '$1$3', '$1$2$4$5', '$1$2$3', '$1$2' ), trim($input)); @@ -122,9 +131,9 @@ function minify_js($input) { // '#(?<!\\\)\\\\\"#', // '#(?<!\\\)\\\\\'#', // Remove comments '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*\s*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*[\n]*#', // Remove unused white-space characters outside the string and regex '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n]*?\/(?=[\.,;]|[gimuy]))|\s*([+\-\=\/%\(\)\{\}\[\]<>\|&\?\!\:;\.,])\s*#s', // Remove the last semicolon '#;+\}#', // Replace `true` with `!0` -
taufik-nurrohman revised this gist
Apr 8, 2015 . 1 changed file with 117 additions and 26 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,60 +1,151 @@ <?php /** * ----------------------------------------------------------------------------------------- * Based on `https://github.com/mecha-cms/mecha-cms/blob/master/system/kernel/converter.php` * ----------------------------------------------------------------------------------------- */ // HTML Minifier function minify_html($input) { if(trim($input) === "") return $input; // Remove extra white-spaces between HTML attributes $input = preg_replace_callback('#<([^\/\s<>!]+?)(?:\s+([^<>]*?)\s*|\s*)(\/?)>#s', function($matches) { return '<' . $matches[1] . preg_replace('#([^\s\=\'"]*?\=([\'"]?).*?\2)(\s+|$)#s', ' $1', $matches[2]) . $matches[3] . '>'; }, $input); return preg_replace( array( // Remove HTML comments except IE comments '#\s*(<\!--(?=\[if).*?-->)\s*|\s*<\!--.*?-->\s*#s', // Do not remove white-space after image and // input tag that is followed by a tag open '#(<(?:img|input)(?:\s[^<>]*?>|>))\s+(?=\<[^\/])#', // Remove two or more white-spaces between tags '#(<\!--.*?-->)|(>)[^\S ]{2,}|[^\S ]{2,}(<)|(>)\s{2,}(<)#s', // Proofing ... // o: tag open, c: tag close, t: text // If `<tag> </tag>` remove white-space // If `</tag> <tag>` keep white-space // If `<tag> <tag>` remove white-space // If `</tag> </tag>` remove white-space // If `<tag> ...</tag>` remove white-spaces // If `</tag> ...<tag>` remove white-spaces // If `<tag> ...<tag>` remove white-spaces // If `</tag> ...</tag>` remove white-spaces // If `abc <tag>` keep white-space // If `<tag> abc` remove white-space // If `abc </tag>` remove white-space // If `</tag> abc` keep white-space // If `abc ...<tag>` keep one white-space // If `<tag> ...abc` remove white-spaces // If `abc ...</tag>` remove white-spaces // If `</tag> ...abc` keep one white-space // If `abc ...<tag>` keep one white-space // If `abc ...</tag>` remove white-spaces '#(<\!--.*?-->)|(<(?:img|input)(?:\s[^<>]*?>|>))\s+(?!\<\/)#s', // o+t | o+o '#(<\!--.*?-->)|(<[^\/\s<>]+(?:\s[^<>]*?>|>))\s+(?=\<[^\/])#s', // o+o '#(<\!--.*?-->)|(<\/[^\/\s<>]+?>)\s+(?=\<\/)#s', // c+c '#(<\!--.*?-->)|(<([^\/\s<>]+)(?:\s[^<>]*?>|>))\s+(<\/\3>)#s', // o+c '#(<\!--.*?-->)|(<[^\/\s<>]+(?:\s[^<>]*?>|>))\s+(?!\<)#s', // o+t '#(<\!--.*?-->)|(?!\>)\s+(<\/[^\/\s<>]+?>)#s', // t+c '#(<\!--.*?-->)|(?!\>)\s+(?=\<[^\/])#s', // t+o '#(<\!--.*?-->)|(<\/[^\/\s<>]+?>)\s+(?!\<)#s', // c+t '#(<\!--.*?-->)|(\/>)\s+(?!\<)#', // o+t // Replace ` ` with ` ` '#(?<= )( ){2}#s', // Proofing ... '#(?<=\>) (?!\s| )#', '#(?<=--\>)(?:\s| )+(?=\<)#' ), array( '$1', '$1 ', '$1$2$3$4$5', '$1$2 ', // o+t | o+o '$1$2', // o+o '$1$2', //c+c '$1$2$4', // o+c '$1$2', // o+t '$1$2', // t+c '$1$2 ', // t+o '$1$2 ', // c+t '$1$2 ', // o+t ' $1', ' ', "" ), trim($input)); } // CSS Minifier => http://ideone.com/Q5USEF + improvement(s) function minify_css($input) { if(trim($input) === "") return $input; return preg_replace( array( // Remove comments '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)#s', // Remove unused white-spaces '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` '#(?<=[:\s])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#s', // Replace `:0 0 0 0` with `:0` '#:0 0 0 0(?=[;\}]|\!important)#s', // Replace `background-position:0` with `background-position:0 0` '#background-position:0(?=[;\}])#s', // Replace `0.6` with `.6`, but only when preceded by `:`, `-`, `,` or a white-space '#(?<=[:\-,\s])0+\.(\d+)#s', // Minify string value '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', // Remove empty selectors '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#si' ), array( '$1', '$1$2$3$4$5$6$7', '$1', ':0', 'background-position:0 0', '.$1', '$1$3', '$1$2$4$5', '$1$2' ), trim($input)); } // JavaScript Minifier function minify_js($input) { if(trim($input) === "") return $input; return preg_replace( array( // '#(?<!\\\)\\\\\"#', // '#(?<!\\\)\\\\\'#', // Remove comments '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*\s*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*[\n\r]*#', // Remove unused white-space characters outside the string and regex '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\.,;]|[gimuy]))|\s*([+\-\=\/%\(\)\{\}\[\]<>\|&\?\!\:;\.,])\s*#s', // Remove the last semicolon '#;+\}#', // Replace `true` with `!0` // '#\btrue\b#', // Replace `false` with `!1` // '#\bfalse\b#', // Minify object attribute except JSON attribute. From `{'foo':'bar'}` to `{foo:'bar'}` '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', // --ibid. From `foo['bar']` to `foo.bar` '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' ), array( // '\\u0022', // '\\u0027', '$1', '$1$2', '}', // '!0', // '!1', '$1$3', '$1.$3' ), trim($input)); } -
taufik-nurrohman revised this gist
Feb 11, 2015 . 1 changed file with 6 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -26,10 +26,10 @@ function minify_css($input) { array( '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|/\*(?>.*?\*/)#s', // Remove comments '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', '#([\s:])(0)(cm|em|ex|in|mm|pc|pt|px|%)#', // Replace `0(cm|em|ex|in|mm|pc|pt|px|%)` with `0` '#:0 0 0 0([;\}])#', // Replace `:0 0 0 0` with `:0` '#background-position:0([;\}])#', // Replace `background-position:0` with `background-position:0 0` '#([\s:])0+\.(\d+)#' // Replace `0.6` to `.6`, but only when preceded by `:` or a white-space ), array( '$1', @@ -47,20 +47,14 @@ function minify_js($input) { if(trim($input) === "") return $input; return preg_replace( array( '#\/\*([\s\S]*?)\*\/|(?<!:)\/\/.*([\n\r]+|$)#', // Remove comments '#(?|\s*(".*?"|\'.*?\'|(?<=[\(=\s])\/.*?\/[gimuy]*(?=[.,;\s]))\s*|\s*([+-=\/%(){}\[\]<>|&?!:;.,])\s*)#s', // Remove unused white-space characters outside the string and regex '#;+\}#' // Remove the last semicolon ), array( "", '$1', '}' ), $input); } -
taufik-nurrohman revised this gist
Jan 19, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function minify_css($input) { return preg_replace( array( '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|/\*(?>.*?\*/)#s', // Remove comments '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', '#([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)#', // Replace `0(px|em|%|in|cm|mm|pc|pt|ex)` with `0` '#:0 0 0 0([;\}])#', // Replace `:0 0 0 0` with `:0` '#background-position:0([;\}])#', // Replace `background-position:0` with `background-position:0 0` -
taufik-nurrohman revised this gist
Jan 18, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -49,7 +49,7 @@ function minify_js($input) { array( '#\/\*([\s\S]+?)\*\/|(?<!:)\/\/.*([\n\r]+|$)#', // Remove comments '#(^|[\n\r])\s*#', // Remove space and new-line characters at the beginning of line '#(?|\s*(".*?"|\'.*?\'|(?<=[\(=\s])\/.*?\/[gimuy]*(?=[.,;\s]))\s*|\s*([+-=\/%(){}\[\]<>|&?!:;,])\s*)#s', // Remove unused space characters outside the string and regex '#;\}#', // Remove the last semicolon '#$#', '#;+$#' -
taufik-nurrohman revised this gist
Jan 12, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -49,7 +49,7 @@ function minify_js($input) { array( '#\/\*([\s\S]+?)\*\/|(?<!:)\/\/.*([\n\r]+|$)#', // Remove comments '#(^|[\n\r])\s*#', // Remove space and new-line characters at the beginning of line '#(?| *(".*?"|\'.*?\'|(?<=[\(=\s])\/.*?\/[gimuy]*(?=[.,;\s])) *| *([+-=\/%(){}\[\]<>|&?!:;,]) *)#s', // Remove unused space characters outside the string and regex '#;\}#', // Remove the last semicolon '#$#', '#;+$#' -
taufik-nurrohman revised this gist
Jan 5, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function minify_css($input) { return preg_replace( array( '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|/\*(?>.*?\*/)#s', // Remove comments '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*+-(?!\d)|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', '#([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)#', // Replace `0(px|em|%|in|cm|mm|pc|pt|ex)` with `0` '#:0 0 0 0([;\}])#', // Replace `:0 0 0 0` with `:0` '#background-position:0([;\}])#', // Replace `background-position:0` with `background-position:0 0` @@ -49,7 +49,7 @@ function minify_js($input) { array( '#\/\*([\s\S]+?)\*\/|(?<!:)\/\/.*([\n\r]+|$)#', // Remove comments '#(^|[\n\r])\s*#', // Remove space and new-line characters at the beginning of line '#(?| *(".*?"|\'.*?\'|(?<=[\(=\s])\/.*?\/[igm]*(?=[.,;\s])) *| *([+-=\/%(){}\[\]<>|&?!:;,]) *)#s', // Remove unused space characters outside the string and regex '#;\}#', // Remove the last semicolon '#$#', '#;+$#' -
taufik-nurrohman revised this gist
Jan 5, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -25,7 +25,7 @@ function minify_css($input) { return preg_replace( array( '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|/\*(?>.*?\*/)#s', // Remove comments '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+]|\s*!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', '#([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)#', // Replace `0(px|em|%|in|cm|mm|pc|pt|ex)` with `0` '#:0 0 0 0([;\}])#', // Replace `:0 0 0 0` with `:0` '#background-position:0([;\}])#', // Replace `background-position:0` with `background-position:0 0` -
taufik-nurrohman revised this gist
Jan 3, 2015 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -48,16 +48,18 @@ function minify_js($input) { return preg_replace( array( '#\/\*([\s\S]+?)\*\/|(?<!:)\/\/.*([\n\r]+|$)#', // Remove comments '#(^|[\n\r])\s*#', // Remove space and new-line characters at the beginning of line '#(?| *(".*?"|\'.*?\'|(?<=[=\(\s])\/.*?\/[igm]*[.,;\s]) *| *([+-=\/%(){}\[\]<>|&?!:;,]) *)#s', // Remove unused space characters outside the string and regex '#;\}#', // Remove the last semicolon '#$#', '#;+$#' ), array( "", "", '$1', '}', ';', ';' ), $input); -
taufik-nurrohman revised this gist
Jan 3, 2015 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -49,14 +49,16 @@ function minify_js($input) { array( '#\/\*([\s\S]+?)\*\/|(?<!:)\/\/.*([\n\r]+|$)#', // Remove comments '#[\n\r\t]\s*#', // Remove space and new-line characters at the beginning of line '#(?| *(".*?"|\'.*?\'|(?<=[=\(\s])\/.*?\/[igm]*[.,;\s]) *| *([+-=\/%(){}\[\]<>|&?!:;,]) *)#s', // Remove unused space characters outside the string and regex '#;\}#', // Remove the last semicolon '#;*$#' ), array( "", "", '$1', '}', ';' ), $input); } -
taufik-nurrohman revised this gist
Jan 3, 2015 . 1 changed file with 6 additions and 6 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -5,10 +5,10 @@ function minify_html($input) { if(trim($input) === "") return $input; return preg_replace( array( '#<\!--(?!\[if)([\s\S]+?)-->#s', // Remove HTML comments except IE comments '#>[^\S ]+#s', '#[^\S ]+<#s', '#>\s{2,}<#s' ), array( "", @@ -24,8 +24,8 @@ function minify_css($input) { if(trim($input) === "") return $input; return preg_replace( array( '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|/\*(?>.*?\*/)#s', // Remove comments '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+-]|\s*!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', '#([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)#', // Replace `0(px|em|%|in|cm|mm|pc|pt|ex)` with `0` '#:0 0 0 0([;\}])#', // Replace `:0 0 0 0` with `:0` '#background-position:0([;\}])#', // Replace `background-position:0` with `background-position:0 0` -
taufik-nurrohman revised this gist
Jan 2, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -27,8 +27,8 @@ function minify_css($input) { '#("(?:[^"\\]++|\\.)*+"|\'(?:[^\'\\\\]++|\\.)*+\')|\/\*(?>.*?\*\/)#s', // Remove comments '#("(?:[^"\\]++|\\.)*+"|\'(?:[^\'\\\\]++|\\.)*+\')|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+-]|\s*!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\]++|\\.)*+"|\'(?:[^\'\\\\]++|\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', '#([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)#', // Replace `0(px|em|%|in|cm|mm|pc|pt|ex)` with `0` '#:0 0 0 0([;\}])#', // Replace `:0 0 0 0` with `:0` '#background-position:0([;\}])#', // Replace `background-position:0` with `background-position:0 0` '#(:|\s)0+\\.(\d+)#' // Replace `0.6` to `.6`, but only when preceded by `:` or a white-space ), array( -
taufik-nurrohman created this gist
Jan 2, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ <?php // HTML Minifier function minify_html($input) { if(trim($input) === "") return $input; return preg_replace( array( '#\<\!--(?!\[if)([\s\S]+?)--\>#s', // Remove HTML comments except IE comments '#\>[^\S ]+#s', '#[^\S ]+\<#s', '#\>\s{2,}\<#s' ), array( "", '>', '<', '><' ), $input); } // CSS Minifier => http://ideone.com/Q5USEF + improvement(s) function minify_css($input) { if(trim($input) === "") return $input; return preg_replace( array( '#("(?:[^"\\]++|\\.)*+"|\'(?:[^\'\\\\]++|\\.)*+\')|\/\*(?>.*?\*\/)#s', // Remove comments '#("(?:[^"\\]++|\\.)*+"|\'(?:[^\'\\\\]++|\\.)*+\')|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~+-]|\s*!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\]++|\\.)*+"|\'(?:[^\'\\\\]++|\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', '#([\s:])(0)(px|em|%|in|cm|mm|pc|pt|ex)#', // Replace `0(px|em|%|in|cm|mm|pc|pt|ex)` with `0` '#:0 0 0 0([;\}])#', // Replace `:0 0 0 0;` with `:0` '#background-position:0([;\}])#', // Replace `background-position:0;` with `background-position:0 0;` '#(:|\s)0+\\.(\d+)#' // Replace `0.6` to `.6`, but only when preceded by `:` or a white-space ), array( '$1', '$1$2$3$4$5$6$7', '$1$2', ':0$1', 'background-position:0 0$1', '$1.$2' ), $input); } // JavaScript Minifier function minify_js($input) { if(trim($input) === "") return $input; return preg_replace( array( '#\/\*([\s\S]+?)\*\/|(?<!:)\/\/.*([\n\r]+|$)#', // Remove comments '#[\n\r\t]\s*#', // Remove space and new-line characters at the beginning of line '#(?| *(".*?"|\'.*?\') *| *(\(\/.*?\/[igm]*,) *| *([+-=\/%(){}\[\]<>|&?!:;,]) *)#s', // Remove unused space characters outside the string and regex '#;\}#' // Remove the last semicolon ), array( "", "", '$1', '}' ), $input); }