{"id":4474,"date":"2015-10-29T22:30:40","date_gmt":"2015-10-30T04:30:40","guid":{"rendered":"http:\/\/blog.eastfist.com\/?p=4474"},"modified":"2015-10-29T22:30:40","modified_gmt":"2015-10-30T04:30:40","slug":"how-to-minify-html-with-notepad","status":"publish","type":"post","link":"https:\/\/eastfist.com\/blog\/2015\/10\/29\/how-to-minify-html-with-notepad\/","title":{"rendered":"How To Minify HTML With Notepad++"},"content":{"rendered":"<p>By Chongchen Saelee<\/p>\n<p>When you want to optimize HTML processing speed, you might want to minify the HTML code. This is done by removing all whitespaces, assuming your code is strongly-typed and syntax and structure is all correct. You can do this manually, which will be a pain, or use the help of an advanced text editor.<\/p>\n<p>Download the latest version of <a href=\"https:\/\/notepad-plus-plus.org\/\">Notepad++<\/a> (as of today, the latest version is 6.8.6). It&#8217;s free and way more robust than your standard Windows Notepad (obviously, if you can&#8217;t tell by the name).<!--more--><\/p>\n<h2>UPDATE: More Comprehensive Minify HTML (Remove Whitespace + Line Breaks)<\/h2>\n<p>I figured out how to use regular expressions (RegEx) via Search and Replace which really finetunes the minifying process. Check this out:<\/p>\n<figure id=\"attachment_4502\" aria-describedby=\"caption-attachment-4502\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_uglyHtml.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_uglyHtml-300x145.png\" alt=\"Notepad++ Ugly Html Code Example\" width=\"300\" height=\"145\" class=\"size-medium wp-image-4502\" \/><\/a><figcaption id=\"caption-attachment-4502\" class=\"wp-caption-text\">Notepad++ Ugly Html Code Example<\/figcaption><\/figure>\n<p>1. Go to Search menu.<br \/>\n2. Click Replace.<br \/>\n3. Enable Regular Expression radio button.<br \/>\n<figure id=\"attachment_4514\" aria-describedby=\"caption-attachment-4514\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_regexSearch.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_regexSearch-300x190.png\" alt=\"Notepad++ Regular Expression (RegEx) Search and Replace\" width=\"300\" height=\"190\" class=\"size-medium wp-image-4514\" \/><\/a><figcaption id=\"caption-attachment-4514\" class=\"wp-caption-text\">Notepad++ Regular Expression (RegEx) Search and Replace<\/figcaption><\/figure><\/p>\n<p>4. Type in Find what: \\s{2,50}<br \/>\n5. Type in Replace with: _ (type single space instead of underscore. not do not type \\s)<br \/>\n6. Find the following regex and replace them as such:<\/p>\n<table style=\"font-size:10pt;padding:0;border:1px solid #000;\">\n<tr colspan=\"3\">\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">Find what:<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">Replace with:<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">Explanation<\/td>\n<\/tr>\n<tr colspan=\"3\">\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">\\s{2,50}<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">_<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">Replace with single space, not an underscore. And don&#8217;t type \\s. What you&#8217;re doing here is finding any matches for spaces \\s with lengths between 2 and 50. The delimiter can actually be more than 50, but it&#8217;s not reasonable. You can put whatever you want if you do it yourself. You want only one space between any two nonspace characters.<\/td>\n<\/tr>\n<tr colspan=\"3\">\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">&gt;\\s{2,50}<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">&gt;<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">Get rid of any space between closing tags and first nonspace character.<\/td>\n<\/tr>\n<tr colspan=\"3\">\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">\\s{2,50}&lt;<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">&lt;<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">Get rid of any space before opening tag and possible nonspace character.<\/td>\n<\/tr>\n<tr colspan=\"3\">\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">&gt;\\r\\n<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">&gt;<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">Remove any linebreaks, aka &#8220;newline&#8221; aka carriage return \\r + line feed \\n that may exist after closing tag.<\/td>\n<\/tr>\n<tr colspan=\"3\">\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">\\r\\n&lt;<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">&lt;<\/td>\n<td style=\"width:33%;border:1px solid #000;padding:5px;\">Remove any linebreaks before opening tag.<\/td>\n<\/tr>\n<\/table>\n<figure id=\"attachment_4512\" aria-describedby=\"caption-attachment-4512\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_minifyHTML.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_minifyHTML-300x145.png\" alt=\"Notepad++ Better Minify HTML\" width=\"300\" height=\"145\" class=\"size-medium wp-image-4512\" \/><\/a><figcaption id=\"caption-attachment-4512\" class=\"wp-caption-text\">Notepad++ Better Minify HTML<\/figcaption><\/figure>\n<p>Of course, you can always save out the steps as a macro. Just follow the instructions from previous tutorial (below). But do note, when you save out this minified HTML file, don&#8217;t save over your original code. You will lose all the formatting and Notepad++ won&#8217;t be able to fold your code for you next time you want to edit it. So save a copy.<\/p>\n<p>Otherwise, you can alter your shortcuts.xml file in %AppData%\\Roaming\\Notepad++ with this xml:<\/p>\n<p><a href=\"http:\/\/files.eastfist.com\/shortcuts_htmlMinify.xml\">shortcuts_htmlMinify.xml<\/a><\/p>\n<figure id=\"attachment_4522\" aria-describedby=\"caption-attachment-4522\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_shortcutsXML.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_shortcutsXML-300x211.png\" alt=\"Notepad++ shortcuts.xml file found in your %AppData%\\Roaming\\Notepad++ folder stores your macros\" width=\"300\" height=\"211\" class=\"size-medium wp-image-4522\" \/><\/a><figcaption id=\"caption-attachment-4522\" class=\"wp-caption-text\">Notepad++ shortcuts.xml file found in your %AppData%\\Roaming\\Notepad++ folder stores your macros<\/figcaption><\/figure>\n<figure id=\"attachment_4523\" aria-describedby=\"caption-attachment-4523\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_shortcutsXMLAdd.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_shortcutsXMLAdd-300x211.png\" alt=\"Notepad++ shortcuts.xml Add new macro\" width=\"300\" height=\"211\" class=\"size-medium wp-image-4523\" \/><\/a><figcaption id=\"caption-attachment-4523\" class=\"wp-caption-text\">Notepad++ shortcuts.xml Add new macro<\/figcaption><\/figure>\n<p>Copy the xml into the Macros XML Group in your shortcuts.xml file. WARNING!! Make sure you backup your original shortcuts.xml file first before you alter it. I can&#8217;t guarantee you it will work. Also, make sure you&#8217;re altering the shortcuts.xml file in your %AppData%\/Roaming\/Notepad++ folder instead of the one in your install folder. Otherwise, just record the macro manually following the steps above.<\/p>\n<h2>Basic Minify HTML (Removing Line Breaks)<\/h2>\n<figure id=\"attachment_4479\" aria-describedby=\"caption-attachment-4479\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_regularHTML.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-4479\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_regularHTML-300x137.png\" alt=\"Notepad++ Normal, clean readable HTML code\" width=\"300\" height=\"137\" \/><\/a><figcaption id=\"caption-attachment-4479\" class=\"wp-caption-text\">Notepad++ Normal, clean readable HTML code<\/figcaption><\/figure>\n<p>1. Go to <strong>Search<\/strong> menu.<br \/>\n2. In <strong>Search Mode<\/strong>, enable <strong>Extended (\\n, \\r, \\t, \\0, \\x&#8230;)<\/strong> radio button.<\/p>\n<figure id=\"attachment_4483\" aria-describedby=\"caption-attachment-4483\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_replaceSettings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-4483\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_replaceSettings-300x191.png\" alt=\"Notepad++ Search and Replace Settings To Remove Whitespace\" width=\"300\" height=\"191\" \/><\/a><figcaption id=\"caption-attachment-4483\" class=\"wp-caption-text\">Notepad++ Search and Replace Settings To Remove Whitespace<\/figcaption><\/figure>\n<p>3. Type in <strong>Find what:<\/strong> <code>&gt;\\r\\n<\/code>. What you&#8217;re doing is replacing any New Line <code>\\r\\n<\/code>, which is comprised of Carriage Return <code>\\r<\/code> + Line Feed <code>\\n<\/code> found after a closing bracket <code>&gt;<\/code> with a regular closing bracket. This brings the next line back to the preceding line.<br \/>\n4. Type in <strong>Replace with:<\/strong> <code>&gt;<\/code><br \/>\n5. Click <strong>Replace All<\/strong>.<br \/>\n6. Type in <strong>Find what:<\/strong> <code>\\r\\n&lt;<\/code><br \/>\n7. Type in <strong>Replace with:<\/strong> <code>&lt;<\/code><br \/>\n8. Click <strong>Replace All<\/strong>.<\/p>\n<figure id=\"attachment_4487\" aria-describedby=\"caption-attachment-4487\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_minifiedHTML.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_minifiedHTML-300x137.png\" alt=\"Notepad++ Minified HTML\" width=\"300\" height=\"137\" class=\"size-medium wp-image-4487\" \/><\/a><figcaption id=\"caption-attachment-4487\" class=\"wp-caption-text\">Notepad++ Minified HTML<\/figcaption><\/figure>\n<p>And to make this process even faster, thank goodness for macros. You can use Notepad++ macro recorder to record these steps in advanced and just call them again the next time you want to minify your HTML. How convenient!<\/p>\n<h2>How To Record an HTML Minify Macro:<\/h2>\n<p>1. Go to Macro menu.<br \/>\n2. Click Start Recording.<br \/>\n<figure id=\"attachment_4489\" aria-describedby=\"caption-attachment-4489\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_startMacro.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_startMacro-300x137.png\" alt=\"Notepad++ Start Recording a Macro\" width=\"300\" height=\"137\" class=\"size-medium wp-image-4489\" \/><\/a><figcaption id=\"caption-attachment-4489\" class=\"wp-caption-text\">Notepad++ Start Recording a Macro<\/figcaption><\/figure><\/p>\n<p>3. Repeat the steps 1 to 8 for Search and Replace as listed above.<br \/>\n4. Go to Macro menu, click Stop Recording.<br \/>\n5. Go to Macro menu, click Save Current Recorded Macro&#8230;<br \/>\n6. Type in &#8220;MinifyHTML&#8221; or whatever you desire.<br \/>\n<figure id=\"attachment_4492\" aria-describedby=\"caption-attachment-4492\" style=\"width: 287px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_saveMacroShortcut.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_saveMacroShortcut.png\" alt=\"Notepad++ Macro Shortcut Settings\" width=\"287\" height=\"200\" class=\"size-full wp-image-4492\" \/><\/a><figcaption id=\"caption-attachment-4492\" class=\"wp-caption-text\">Notepad++ Macro Shortcut Settings<\/figcaption><\/figure><\/p>\n<p>7. Now when you click Macro menu, you will see your previously recorded macro &#8220;MinifyHTML&#8221; and all you have to do is click that for immediate minifying! Sweet!<br \/>\n<figure id=\"attachment_4491\" aria-describedby=\"caption-attachment-4491\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_macroSaved.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/blog.eastfist.com\/wp-content\/uploads\/notepad-_macroSaved-300x137.png\" alt=\"Notepad++ Macro Shortcut Saved\" width=\"300\" height=\"137\" class=\"size-medium wp-image-4491\" \/><\/a><figcaption id=\"caption-attachment-4491\" class=\"wp-caption-text\">Notepad++ Macro Shortcut Saved<\/figcaption><\/figure><\/p>\n<h2>Alternatively, but not best results:<\/h2>\n<p>1. Go to Edit menu.<br \/>\n2. Go to Blank Operations<br \/>\n3. Select &#8216;Remove Unnecessary Blank and EOL&#8217; or &#8216;EOL to Space&#8217;.<\/p>\n<p>But this result leaves space padding for content inside tags, which is optimal minify-sation. I haven&#8217;t found a feature in the Blank Operations that complete the minify process either.<\/p>\n<h2>Summary<\/h2>\n<p>This method is only to remove linebreaks. Of course, the comprehensive minify process would include fixing unclosed HTML tags (those that require it anyway), minimizing spaces in innerHTML content, removing comments, etc. Anyway, I hope this very basic method helps!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>By Chongchen Saelee When you want to optimize HTML processing speed, you might want to minify the HTML code. This is done by removing all whitespaces, assuming your code is strongly-typed and syntax and structure is all correct. You can do this manually, which will be a pain, or use the help of an advanced [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-4474","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/posts\/4474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/comments?post=4474"}],"version-history":[{"count":0,"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/posts\/4474\/revisions"}],"wp:attachment":[{"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/media?parent=4474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/categories?post=4474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eastfist.com\/blog\/wp-json\/wp\/v2\/tags?post=4474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}