minify_html function
(html)
| 102 | |
| 103 | |
| 104 | def minify_html(html): |
| 105 | """ |
| 106 | minify_html function |
| 107 | """ |
| 108 | # Combine multiple regex operations into one for better performance |
| 109 | patterns = [ |
| 110 | (r"<!--.*?-->", "", re.DOTALL), |
| 111 | (r">\s+<", "><", 0), |
| 112 | (r"\s+>", ">", 0), |
| 113 | (r"<\s+", "<", 0), |
| 114 | (r"\s+", " ", 0), |
| 115 | (r"\s*=\s*", "=", 0), |
| 116 | ] |
| 117 | |
| 118 | for pattern, repl, flags in patterns: |
| 119 | html = re.sub(pattern, repl, html, flags=flags) |
| 120 | |
| 121 | return html.strip() |
| 122 | |
| 123 | |
| 124 | def reduce_html(html, reduction): |
no outgoing calls