Skip to content

Instantly share code, notes, and snippets.

@turivishal
Last active December 11, 2020 11:56
Show Gist options
  • Save turivishal/001530d1fa747e4faf2f612d6c594637 to your computer and use it in GitHub Desktop.
Save turivishal/001530d1fa747e4faf2f612d6c594637 to your computer and use it in GitHub Desktop.
Monify HTML using JavaScript
let html = `
Welcome to City
<table width="100%" bgcolor="#fff" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td>
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="devicewidth">
<tbody>
<tr>
<td width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0" align="center" class="devicewidth">
<tbody>
<tr>
<td width="100%" height="10"></td>
</tr>
<tr>
<td width="100%" height="10"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
`;
let minifyHtml = html.replace(/^\s+|\r\n|\n|\r|(>)\s+(<)|\s+$/gm, '$1$2');
alert(minifyHtml);
console.log(minifyHtml);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment