Created
January 1, 2016 04:08
-
-
Save JavaScript-Packer/e4cee07510e946e5c5ca to your computer and use it in GitHub Desktop.
Minify HTML, it can be harsh, so test the results.
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
| function minhtm(r, R) { | |
| R = "replace"; | |
| return r[R](/>(\n| | )*</g, "><")[R](/[a-z-]+=""/g, "")[R](/"([^ ]*)"/g, "$1")[R](/<\/li>/, ""); | |
| } | |
| var minifyHtml = function() { | |
| var r = /<(pre|style|script(?![^>]*?src))[^>]*>[\s\S]*?<\/\1>/gi, e = /("|')(?:\\\1|[^\1])*?\1/g, n = /__str(\d+)__/g, t = /<preserved>/g, c = /<!--(?!\s*?\[\s*?if)[\s\S]*?-->/gi, s = "", i = /(?:\s+=|=\s+)(?=[^<]*>)/g, p = "=", a = /\s*>/g, l = ">", u = /\s+(?=[^<]*>)/g, g = " ", o = />\s+</g, f = "><", _ = /(<\w+ )([^>]*)/g, v = function(r, e, n) { | |
| return e + n.split(" ").sort().join(" "); | |
| }, m = /<.*?class=("|')([^\1]*)\1/gi, h = function(r, e, n, R) { | |
| var t = n.split(/\s\s*/g).sort().join(" "); | |
| return r[R](n, t); | |
| }; | |
| return function(d,R) {R = "replace"; | |
| var y = [], j = [], S = function(r) { | |
| return y.push(r), "<preserved>"; | |
| }, w = function() { | |
| return y.shift(); | |
| }, H = function(r) { | |
| var e = j.length; | |
| return j[e] = r, "__str" + e + "__"; | |
| }, z = function(r, e) { | |
| return j[+e]; | |
| }; | |
| return d[R](e, H)[R](r, S)[R](c, s)[R](i, p)[R](a, l)[R](u, g)[R](o, f)[R](_, v)[R](t, w)[R](n, z)[R](m, h).trim(); | |
| }; | |
| }(); | |
| //usage: document.getElementById('outz').value=minhtm(minifyHtml(document.getElementById('inz').value)); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Minified to 925 bytes: