{"componentChunkName":"component---src-templates-tags-js","path":"/tags/unused/","result":{"data":{"allMarkdownRemark":{"totalCount":1,"edges":[{"node":{"id":"aecc03c1-62eb-5fb9-9057-340b807540d2","html":"<p>Unused CSS is a one of the issues most web applications suffer when it comes to performance and page load time.</p>\n<!--more-->\n<h2 id=\"disclaimer\" style=\"position:relative;\"><a href=\"#disclaimer\" aria-label=\"disclaimer permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Disclaimer</h2>\n<p>Apart from option one in this post, most of the time you will need a tool and some manual intervention to be able to safely eliminate unused CSS. These tools are great in a sense that they will let you know what you don’t know; which classes in your template files are not used.</p>\n<p>These tools can’t work with complex scenarios like when you have JavaScript adding a DOM element in the template.</p>\n<p>They will have problems with dynamic templates in Single Page Applications (SPA) or when your template changes based on a state on your server side code.</p>\n<h2 id=\"problem\" style=\"position:relative;\"><a href=\"#problem\" aria-label=\"problem permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Problem</h2>\n<p>As I said, Unused CSS is a one of the issues most web applications suffer when it comes to performance and page load time.</p>\n<p>This even gets worst when you use a CSS library like Tailwind, or an older versions of CSS frameworks like <a href=\"https://getbootstrap.com/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Bootstrap</a> or <a href=\"https://material.io/design/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Material Design</a>.</p>\n<div class=\"custom-block info\"><div class=\"custom-block-body\"> <strong>Note:</strong> most CSS frameworks have moved to modular structure where you could import only the part you need without having to include the whole bundle.</div></div>\n<h2 id=\"best-and-safest-approach\" style=\"position:relative;\"><a href=\"#best-and-safest-approach\" aria-label=\"best and safest approach permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Best and safest approach</h2>\n<p>To my opinion, the best and safest approach is to be careful and get rid of any CSS file or part you remove from your HTML or template files. Do not be lazy or ignorance when it comes to tech debts like this. If you’re involved in a green field project, make sure you do not copy paste large chunks of CSS from somewhere you’re looking into without realising which parts are actually used.</p>\n<p>You can manually find your unused CSS using the <a href=\"https://developers.google.com/web/tools/chrome-devtools/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">DevTools</a> in <a href=\"https://www.google.com/chrome/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google Chrome</a> with following these steps:</p>\n<ol>\n<li>Open the Chrome DevTools using <kbd>F12</kbd> or <kbd>Ctrl</kbd> <kbd>Shift</kbd> <kbd>J</kbd> on Windows or <kbd>Command</kbd> <kbd>Option</kbd> <kbd>J</kbd> on Mac.</li>\n<li>Open the command menu by pressing <kbd>Ctrl</kbd> <kbd>Shift</kbd> <kbd>P</kbd> on Windows or <kbd>Command</kbd> <kbd>Shift</kbd> <kbd>J</kbd> on Mac.</li>\n<li>Type in “Coverage” and click on the “Show Coverage” option</li>\n<li>Click on reload button at the coverage tab.</li>\n<li>Select a CSS file from the Coverage tab which will open the file up in the Sources tab.</li>\n</ol>\n<p>Any CSS rule which has a solid green line on the left side is used. Those with a red line are not:</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 1080px; \"\n    >\n      <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 63.33333333333333%; position: relative; bottom: 0; left: 0; background-image: url('data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAANABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAgADBf/EABQBAQAAAAAAAAAAAAAAAAAAAAH/2gAMAwEAAhADEAAAAevoiijD/8QAGBAAAgMAAAAAAAAAAAAAAAAAABEBEiD/2gAIAQEAAQUCrOEI/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFREBAQAAAAAAAAAAAAAAAAAAEBH/2gAIAQIBAT8Bp//EABYQAAMAAAAAAAAAAAAAAAAAAAEgMv/aAAgBAQAGPwKy3//EABkQAAMBAQEAAAAAAAAAAAAAAAABESFR0f/aAAgBAQABPyG78xcek4SMht4NT//aAAwDAQACAAMAAAAQhM//xAAWEQEBAQAAAAAAAAAAAAAAAAABEBH/2gAIAQMBAT8QDJ//xAAWEQEBAQAAAAAAAAAAAAAAAAABEDH/2gAIAQIBAT8QU7P/xAAbEAEBAAIDAQAAAAAAAAAAAAABEQAhMUFx0f/aAAgBAQABPxAI0iXj4wpEY1XvF3QnuaAPWFUOctIATP/Z'); background-size: cover; display: block;\"\n  ></span>\n  <img\n        class=\"gatsby-resp-image-image\"\n        alt=\"Unused CSS\"\n        title=\"\"\n        src=\"/static/699d167c408e183c1938a4a412aa6a32/47311/csscoverage.jpg\"\n        srcset=\"/static/699d167c408e183c1938a4a412aa6a32/6f81f/csscoverage.jpg 270w,\n/static/699d167c408e183c1938a4a412aa6a32/09d21/csscoverage.jpg 540w,\n/static/699d167c408e183c1938a4a412aa6a32/47311/csscoverage.jpg 1080w,\n/static/699d167c408e183c1938a4a412aa6a32/0047d/csscoverage.jpg 1620w,\n/static/699d167c408e183c1938a4a412aa6a32/274e1/csscoverage.jpg 2160w,\n/static/699d167c408e183c1938a4a412aa6a32/be310/csscoverage.jpg 3227w\"\n        sizes=\"(max-width: 1080px) 100vw, 1080px\"\n        style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n        loading=\"lazy\"\n        decoding=\"async\"\n      />\n    </span></p>\n<div class=\"custom-block warning\"><div class=\"custom-block-body\"> <strong>Warning:</strong> Just because a rule isn’t used on this page doesn’t mean it’s not used elsewhere. You would ideally check the coverage on all pages and combine the result for a better overview.\r\n<br/></div></div>\n<h2 id=\"tools\" style=\"position:relative;\"><a href=\"#tools\" aria-label=\"tools permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Tools</h2>\n<p>Some times you cannot adhere to ☝🏼 point because of various reasons. Such as you got involved in a brown field project or the code base is to large to be able to refactor and fix the issue in a timely fashion.</p>\n<p>In this case you might be looking at some tool to automate the process and do the clean-up systematically during build time. Fortunately there are many tools available which help you with this. I will cover some famous ones and mention a short list at the end for good measure 😉.</p>\n<h2 id=\"1-purifycss\" style=\"position:relative;\"><a href=\"#1-purifycss\" aria-label=\"1 purifycss permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>1. PurifyCSS</h2>\n<p><a href=\"https://github.com/purifycss/purifycss\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">PurifyCSS</a> is tool that can analyse your files, go through code, and figure out what classes are not used. Most of the time when you have static HTML files this tool can eliminate nearly all your unused CSS.</p>\n<p>Apart from that, it can also work to a degree with Single Page Applications (SPA).</p>\n<h3 id=\"setup\" style=\"position:relative;\"><a href=\"#setup\" aria-label=\"setup permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Setup</h3>\n<p><strong>Standalone</strong></p>\n<p>You can install this package via <code class=\"language-text\">npm</code>:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"56624076494858350000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npm i -D purify-css`, `56624076494858350000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-bash line-numbers\"><code class=\"language-bash\"><span class=\"token function\">npm</span> i <span class=\"token parameter variable\">-D</span> purify-css</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span></span></pre></div>\n<p>And some basic usage:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"86240383039048660000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`import purify from 'purify-css'\r\nconst purify = require('purify-css')\r\n\r\nlet content = ''\r\nlet css = ''\r\nlet options = {\r\n  output: 'filepath/output.css',\r\n}\r\npurify(content, css, options)`, `86240383039048660000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-js line-numbers\"><code class=\"language-js\"><span class=\"token keyword\">import</span> purify <span class=\"token keyword\">from</span> <span class=\"token string\">'purify-css'</span>\r\n<span class=\"token keyword\">const</span> purify <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'purify-css'</span><span class=\"token punctuation\">)</span>\r\n\r\n<span class=\"token keyword\">let</span> content <span class=\"token operator\">=</span> <span class=\"token string\">''</span>\r\n<span class=\"token keyword\">let</span> css <span class=\"token operator\">=</span> <span class=\"token string\">''</span>\r\n<span class=\"token keyword\">let</span> options <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\r\n  <span class=\"token literal-property property\">output</span><span class=\"token operator\">:</span> <span class=\"token string\">'filepath/output.css'</span><span class=\"token punctuation\">,</span>\r\n<span class=\"token punctuation\">}</span>\r\n<span class=\"token function\">purify</span><span class=\"token punctuation\">(</span>content<span class=\"token punctuation\">,</span> css<span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">)</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<p>If you’re wondering well, this is not gonna help me, you might be right. But this is the simplest form. In fact in the <code class=\"language-text\">purify</code> command, <code class=\"language-text\">content</code> and <code class=\"language-text\">css</code> parameters can be an <code class=\"language-text\">Array</code> of <a href=\"https://github.com/isaacs/node-glob\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">glob</a> file patterns. Now you see the bigger picture and how this can help.</p>\n<p>Now let’s make it a bit more complex.</p>\n<p><strong>via Grunt</strong></p>\n<p>First you need to install the grunt package:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"1090840202524012700\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npm install grunt-purifycss --save-dev`, `1090840202524012700`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-bash line-numbers\"><code class=\"language-bash\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> grunt-purifycss --save-dev</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span></span></pre></div>\n<p>And then use it:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"95857538814339150000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`grunt.initConfig({\r\n  purifycss: {\r\n    options: {},\r\n    target: {\r\n      src: ['path/to/*.html', 'path/to/*.js'],\r\n      css: ['path/to/*.css'],\r\n      dest: 'tmp/purestyles.css',\r\n    },\r\n  },\r\n})`, `95857538814339150000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-js line-numbers\"><code class=\"language-js\">grunt<span class=\"token punctuation\">.</span><span class=\"token function\">initConfig</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\r\n  <span class=\"token literal-property property\">purifycss</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\r\n    <span class=\"token literal-property property\">options</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span><span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">target</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\r\n      <span class=\"token literal-property property\">src</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'path/to/*.html'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'path/to/*.js'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n      <span class=\"token literal-property property\">css</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'path/to/*.css'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n      <span class=\"token literal-property property\">dest</span><span class=\"token operator\">:</span> <span class=\"token string\">'tmp/purestyles.css'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<p>This will handle even scenarios when you have a class added using JavaScript 😍. So this will be picked up:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"2828406569132902000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`<!-- html -->\r\n<!-- class directly on element -->\r\n<div class=&quot;button-active&quot;>click</div>`, `2828406569132902000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"html\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-html line-numbers\"><code class=\"language-html\"><span class=\"token comment\">&lt;!-- html --></span>\r\n<span class=\"token comment\">&lt;!-- class directly on element --></span>\r\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;</span>div</span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>button-active<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>click<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;/</span>div</span><span class=\"token punctuation\">></span></span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span></span></pre></div>\n<p>Or in JavaScript:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"14926848766959600000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`// javascript\r\n// Anytime your class name is together in your files, it will find it.\r\n\\$(button).addClass('button-active')`, `14926848766959600000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-js line-numbers\"><code class=\"language-js\"><span class=\"token comment\">// javascript</span>\r\n<span class=\"token comment\">// Anytime your class name is together in your files, it will find it.</span>\r\n<span class=\"token function\">$</span><span class=\"token punctuation\">(</span>button<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addClass</span><span class=\"token punctuation\">(</span><span class=\"token string\">'button-active'</span><span class=\"token punctuation\">)</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span></span></pre></div>\n<p>Or even a bit more complex scenario:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"31829207410996306000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`// Can detect if class is split.\r\nvar half = 'button-';\r\n\\$(button).addClass(half + 'active');\r\n\r\n// Can detect if class is joined.\r\nvar dynamicClass = ['button', 'active'].join('-');\r\n\\$(button).addClass(dynamicClass);\r\n\r\n// Can detect various more ways, including all Javascript frameworks.\r\n// A React example.\r\nvar classes = classNames({\r\n  'button-active': this.state.buttonActive\r\n});\r\n\r\nreturn (\r\n  <button className={classes}>Submit</button>;\r\n);`, `31829207410996306000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-js line-numbers\"><code class=\"language-js\"><span class=\"token comment\">// Can detect if class is split.</span>\r\n<span class=\"token keyword\">var</span> half <span class=\"token operator\">=</span> <span class=\"token string\">'button-'</span><span class=\"token punctuation\">;</span>\r\n<span class=\"token function\">$</span><span class=\"token punctuation\">(</span>button<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addClass</span><span class=\"token punctuation\">(</span>half <span class=\"token operator\">+</span> <span class=\"token string\">'active'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\r\n\r\n<span class=\"token comment\">// Can detect if class is joined.</span>\r\n<span class=\"token keyword\">var</span> dynamicClass <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'button'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'active'</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span><span class=\"token string\">'-'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\r\n<span class=\"token function\">$</span><span class=\"token punctuation\">(</span>button<span class=\"token punctuation\">)</span><span class=\"token punctuation\">.</span><span class=\"token function\">addClass</span><span class=\"token punctuation\">(</span>dynamicClass<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\r\n\r\n<span class=\"token comment\">// Can detect various more ways, including all Javascript frameworks.</span>\r\n<span class=\"token comment\">// A React example.</span>\r\n<span class=\"token keyword\">var</span> classes <span class=\"token operator\">=</span> <span class=\"token function\">classNames</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\r\n  <span class=\"token string-property property\">'button-active'</span><span class=\"token operator\">:</span> <span class=\"token keyword\">this</span><span class=\"token punctuation\">.</span>state<span class=\"token punctuation\">.</span>buttonActive\r\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\r\n\r\n<span class=\"token keyword\">return</span> <span class=\"token punctuation\">(</span>\r\n  <span class=\"token operator\">&lt;</span>button className<span class=\"token operator\">=</span><span class=\"token punctuation\">{</span>classes<span class=\"token punctuation\">}</span><span class=\"token operator\">></span>Submit<span class=\"token operator\">&lt;</span><span class=\"token operator\">/</span>button<span class=\"token operator\">></span><span class=\"token punctuation\">;</span>\r\n<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<div class=\"custom-block warning\"><div class=\"custom-block-body\"> <strong>Warning</strong>: The Webpack plugin for purifycss is deprecated. You will need to use Purgecss which I will go through later on.</div></div>\n<p><strong>CLI</strong></p>\n<p>Install the CLI:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"74254379111972500000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npm install -g purify-css`, `74254379111972500000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-bash line-numbers\"><code class=\"language-bash\"><span class=\"token function\">npm</span> <span class=\"token function\">install</span> <span class=\"token parameter variable\">-g</span> purify-css</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span></span></pre></div>\n<p>And you can see the help using <code class=\"language-text\">-h</code> param:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"83067729873434790000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`purifycss -h\r\n\r\npurifycss <css> <content> [option]\r\n\r\nOptions:\r\n  -m, --min        Minify CSS                                   [boolean] [default: false]\r\n  -o, --out        Filepath to write purified css to                              [string]\r\n  -i, --info       Logs info on how much css was removed        [boolean] [default: false]\r\n  -r, --rejected   Logs the CSS rules that were removed         [boolean] [default: false]\r\n  -w, --whitelist  List of classes that should not be removed        [array] [default: []]\r\n  -h, --help       Show help                                                     [boolean]\r\n  -v, --version    Show version number                                           [boolean]`, `83067729873434790000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-bash line-numbers\"><code class=\"language-bash\">purifycss <span class=\"token parameter variable\">-h</span>\r\n\r\npurifycss <span class=\"token operator\">&lt;</span>css<span class=\"token operator\">></span> <span class=\"token operator\">&lt;</span>content<span class=\"token operator\">></span> <span class=\"token punctuation\">[</span>option<span class=\"token punctuation\">]</span>\r\n\r\nOptions:\r\n  -m, <span class=\"token parameter variable\">--min</span>        Minify CSS                                   <span class=\"token punctuation\">[</span>boolean<span class=\"token punctuation\">]</span> <span class=\"token punctuation\">[</span>default: false<span class=\"token punctuation\">]</span>\r\n  -o, <span class=\"token parameter variable\">--out</span>        Filepath to <span class=\"token function\">write</span> purified css to                              <span class=\"token punctuation\">[</span>string<span class=\"token punctuation\">]</span>\r\n  -i, <span class=\"token parameter variable\">--info</span>       Logs info on how much css was removed        <span class=\"token punctuation\">[</span>boolean<span class=\"token punctuation\">]</span> <span class=\"token punctuation\">[</span>default: false<span class=\"token punctuation\">]</span>\r\n  -r, <span class=\"token parameter variable\">--rejected</span>   Logs the CSS rules that were removed         <span class=\"token punctuation\">[</span>boolean<span class=\"token punctuation\">]</span> <span class=\"token punctuation\">[</span>default: false<span class=\"token punctuation\">]</span>\r\n  -w, <span class=\"token parameter variable\">--whitelist</span>  List of classes that should not be removed        <span class=\"token punctuation\">[</span>array<span class=\"token punctuation\">]</span> <span class=\"token punctuation\">[</span>default: <span class=\"token punctuation\">[</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">]</span>\r\n  -h, <span class=\"token parameter variable\">--help</span>       Show <span class=\"token builtin class-name\">help</span>                                                     <span class=\"token punctuation\">[</span>boolean<span class=\"token punctuation\">]</span>\r\n  -v, <span class=\"token parameter variable\">--version</span>    Show version number                                           <span class=\"token punctuation\">[</span>boolean<span class=\"token punctuation\">]</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<h3 id=\"stats\" style=\"position:relative;\"><a href=\"#stats\" aria-label=\"stats permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Stats</h3>\n<p>This library can help you big time. It’s pretty effective and works on complex scenarios. But as I mentioned before you will need to have good tests to able to find out if anything is messed up after clean-up.</p>\n<blockquote>\n<p>In terms of Boostrap, PurifyCSS can reduce up to ~ 33.8% of unused CSS.</p>\n</blockquote>\n<h2 id=\"2-purgecss\" style=\"position:relative;\"><a href=\"#2-purgecss\" aria-label=\"2 purgecss permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>2. Purgecss</h2>\n<p><a href=\"https://github.com/FullHuman/Purgecss\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Purgecss</a> is another powerful tool to remove unused CSS. It can be used as part of your development workflow. It comes with a JavaScript API, a CLI, and plugins for popular build tools.</p>\n<h3 id=\"cli\" style=\"position:relative;\"><a href=\"#cli\" aria-label=\"cli permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>CLI</h3>\n<p>You can install <code class=\"language-text\">Purgecss</code> globally or using <code class=\"language-text\">npx</code>.</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"56341361745574740000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npm i -g Purgecss`, `56341361745574740000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-bash line-numbers\"><code class=\"language-bash\"><span class=\"token function\">npm</span> i <span class=\"token parameter variable\">-g</span> Purgecss</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span></span></pre></div>\n<p>And use it:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"64623950512630415000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`Purgecss --css <css> --content <content> [option]`, `64623950512630415000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-bash line-numbers\"><code class=\"language-bash\">Purgecss <span class=\"token parameter variable\">--css</span> <span class=\"token operator\">&lt;</span>css<span class=\"token operator\">></span> <span class=\"token parameter variable\">--content</span> <span class=\"token operator\">&lt;</span>content<span class=\"token operator\">></span> <span class=\"token punctuation\">[</span>option<span class=\"token punctuation\">]</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span></span></pre></div>\n<p>As you can see, the API is very similar to <code class=\"language-text\">PurifyCSS</code>, but of course options would be different.</p>\n<h3 id=\"via-webpack\" style=\"position:relative;\"><a href=\"#via-webpack\" aria-label=\"via webpack permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Via Webpack</h3>\n<p>You should install the plugin first:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"30699306529128202000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`npm i -D Purgecss-webpack-plugin`, `30699306529128202000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"bash\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-bash line-numbers\"><code class=\"language-bash\"><span class=\"token function\">npm</span> i <span class=\"token parameter variable\">-D</span> Purgecss-webpack-plugin</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span></span></pre></div>\n<p>And the add it to your Webpack config:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"29895301509658313000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`const path = require('path')\r\nconst glob = require('glob')\r\nconst ExtractTextPlugin = require('extract-text-webpack-plugin')\r\nconst PurgecssPlugin = require('Purgecss-webpack-plugin')\r\n\r\nconst PATHS = {\r\n  src: path.join(__dirname, 'src'),\r\n}\r\n\r\nmodule.exports = {\r\n  entry: './src/index.js',\r\n  output: {\r\n    filename: 'bundle.js',\r\n    path: path.join(__dirname, 'dist'),\r\n  },\r\n  module: {\r\n    rules: [\r\n      {\r\n        test: /\\.css\\$/,\r\n        use: ExtractTextPlugin.extract({\r\n          fallback: 'style-loader',\r\n          use: 'css-loader?sourceMap',\r\n        }),\r\n      },\r\n    ],\r\n  },\r\n  plugins: [\r\n    new ExtractTextPlugin('[name].css?[hash]'),\r\n    new PurgecssPlugin({\r\n      paths: glob.sync(\\`\\${PATHS.src}/**/*\\`, {\r\n        nodir: true,\r\n      }),\r\n    }),\r\n  ],\r\n}`, `29895301509658313000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-js line-numbers\"><code class=\"language-js\"><span class=\"token keyword\">const</span> path <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'path'</span><span class=\"token punctuation\">)</span>\r\n<span class=\"token keyword\">const</span> glob <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'glob'</span><span class=\"token punctuation\">)</span>\r\n<span class=\"token keyword\">const</span> ExtractTextPlugin <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'extract-text-webpack-plugin'</span><span class=\"token punctuation\">)</span>\r\n<span class=\"token keyword\">const</span> PurgecssPlugin <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'Purgecss-webpack-plugin'</span><span class=\"token punctuation\">)</span>\r\n\r\n<span class=\"token keyword\">const</span> <span class=\"token constant\">PATHS</span> <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\r\n  <span class=\"token literal-property property\">src</span><span class=\"token operator\">:</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>__dirname<span class=\"token punctuation\">,</span> <span class=\"token string\">'src'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\r\n<span class=\"token punctuation\">}</span>\r\n\r\nmodule<span class=\"token punctuation\">.</span>exports <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\r\n  <span class=\"token literal-property property\">entry</span><span class=\"token operator\">:</span> <span class=\"token string\">'./src/index.js'</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token literal-property property\">output</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\r\n    <span class=\"token literal-property property\">filename</span><span class=\"token operator\">:</span> <span class=\"token string\">'bundle.js'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">path</span><span class=\"token operator\">:</span> path<span class=\"token punctuation\">.</span><span class=\"token function\">join</span><span class=\"token punctuation\">(</span>__dirname<span class=\"token punctuation\">,</span> <span class=\"token string\">'dist'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token literal-property property\">module</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\r\n    <span class=\"token literal-property property\">rules</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\r\n      <span class=\"token punctuation\">{</span>\r\n        <span class=\"token literal-property property\">test</span><span class=\"token operator\">:</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">\\.css$</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">,</span>\r\n        <span class=\"token literal-property property\">use</span><span class=\"token operator\">:</span> ExtractTextPlugin<span class=\"token punctuation\">.</span><span class=\"token function\">extract</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\r\n          <span class=\"token literal-property property\">fallback</span><span class=\"token operator\">:</span> <span class=\"token string\">'style-loader'</span><span class=\"token punctuation\">,</span>\r\n          <span class=\"token literal-property property\">use</span><span class=\"token operator\">:</span> <span class=\"token string\">'css-loader?sourceMap'</span><span class=\"token punctuation\">,</span>\r\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\r\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token literal-property property\">plugins</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\r\n    <span class=\"token keyword\">new</span> <span class=\"token class-name\">ExtractTextPlugin</span><span class=\"token punctuation\">(</span><span class=\"token string\">'[name].css?[hash]'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token keyword\">new</span> <span class=\"token class-name\">PurgecssPlugin</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">{</span>\r\n      <span class=\"token literal-property property\">paths</span><span class=\"token operator\">:</span> glob<span class=\"token punctuation\">.</span><span class=\"token function\">sync</span><span class=\"token punctuation\">(</span><span class=\"token template-string\"><span class=\"token template-punctuation string\">`</span><span class=\"token interpolation\"><span class=\"token interpolation-punctuation punctuation\">${</span><span class=\"token constant\">PATHS</span><span class=\"token punctuation\">.</span>src<span class=\"token interpolation-punctuation punctuation\">}</span></span><span class=\"token string\">/**/*</span><span class=\"token template-punctuation string\">`</span></span><span class=\"token punctuation\">,</span> <span class=\"token punctuation\">{</span>\r\n        <span class=\"token literal-property property\">nodir</span><span class=\"token operator\">:</span> <span class=\"token boolean\">true</span><span class=\"token punctuation\">,</span>\r\n      <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n<span class=\"token punctuation\">}</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<p>For more information please refer to <a href=\"https://www.Purgecss.com/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">their documents</a>.</p>\n<h2 id=\"3-uncss\" style=\"position:relative;\"><a href=\"#3-uncss\" aria-label=\"3 uncss permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>3. UnCSS</h2>\n<p><a href=\"https://github.com/uncss/uncss\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">UnCSS</a> is another tool to help you remove your unused CSS. But this tool is a bit different in sense that it will load your files in <a href=\"https://github.com/jsdom/jsdom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">jsdom</a>, then will parse all the stylesheets with PostCSS.</p>\n<p>Once finished, <code class=\"language-text\">document.querySelector</code> will filter out selectors that are not found in the HTML files. And finally, the remaining rules are converted back to CSS.</p>\n<div class=\"custom-block info\"><div class=\"custom-block-body\"> <strong>Note:</strong> The best thing about this library which I am in love with, is their <a href=\"https://uncss-online.com/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">unofficial server</a> where you can paste your HTML and CSS it will show you the shortened CSS online.</div></div>\n<h3 id=\"install\" style=\"position:relative;\"><a href=\"#install\" aria-label=\"install permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Install</h3>\n<p>Again you can use <code class=\"language-text\">npm</code> to install it or use <code class=\"language-text\">npx</code>:</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-text line-numbers\"><code class=\"language-text\">npm i -g uncss</code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span></span></pre></div>\n<p>You can use UnCSS with node:</p>\n<div\n              class=\"gatsby-code-button-container\"\n              data-toaster-id=\"95502507239089080000\"\n              data-toaster-class=\"gatsby-code-button-toaster\"\n              data-toaster-text-class=\"gatsby-code-button-toaster-text\"\n              data-toaster-text=\"Copied to clipboard ✅\"\n              data-toaster-duration=\"3500\"\n              onClick=\"copyToClipboard(`var uncss = require('uncss')\r\n\r\nvar files = [\r\n    'my',\r\n    'array',\r\n    'of',\r\n    'HTML',\r\n    'files',\r\n    'or',\r\n    'http://urls.com',\r\n  ],\r\n  options = {\r\n    ignore: ['#added_at_runtime', /test\\-[0-9]+/],\r\n    media: [\r\n      '(min-width: 700px) handheld and (orientation: landscape)',\r\n    ],\r\n    csspath: '../public/css/',\r\n    raw: 'h1 { color: green }',\r\n    stylesheets: [\r\n      'lib/bootstrap/dist/css/bootstrap.css',\r\n      'src/public/css/main.css',\r\n    ],\r\n    ignoreSheets: [/fonts.googleapis/],\r\n    timeout: 1000,\r\n    htmlroot: 'public',\r\n    report: false,\r\n    banner: false,\r\n    uncssrc: '.uncssrc',\r\n    userAgent:\r\n      'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)',\r\n    inject: function(window) {\r\n      window.document\r\n        .querySelector('html')\r\n        .classList.add('no-csscalc', 'csscalc')\r\n    },\r\n  }\r\n\r\nuncss(files, options, function(error, output) {\r\n  console.log(output)\r\n})\r\n\r\n/* Look Ma, no options! */\r\nuncss(files, function(error, output) {\r\n  console.log(output)\r\n})\r\n\r\n/* Specifying raw HTML */\r\nvar rawHtml = '...'\r\n\r\nuncss(rawHtml, options, function(error, output) {\r\n  console.log(output)\r\n})`, `95502507239089080000`)\"\n            >\n              <div\n                class=\"gatsby-code-button\"\n                data-tooltip=\"\"\n              >\n                Copy<svg class=\"gatsby-code-button-icon\" xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path fill=\"none\" d=\"M0 0h24v24H0V0z\"/><path d=\"M16 1H2v16h2V3h12V1zm-1 4l6 6v12H6V5h9zm-1 7h5.5L14 6.5V12z\"/></svg>\n              </div>\n            </div>\n<div class=\"gatsby-highlight\" data-language=\"js\"><pre style=\"counter-reset: linenumber NaN\" class=\"language-js line-numbers\"><code class=\"language-js\"><span class=\"token keyword\">var</span> uncss <span class=\"token operator\">=</span> <span class=\"token function\">require</span><span class=\"token punctuation\">(</span><span class=\"token string\">'uncss'</span><span class=\"token punctuation\">)</span>\r\n\r\n<span class=\"token keyword\">var</span> files <span class=\"token operator\">=</span> <span class=\"token punctuation\">[</span>\r\n    <span class=\"token string\">'my'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token string\">'array'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token string\">'of'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token string\">'HTML'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token string\">'files'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token string\">'or'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token string\">'http://urls.com'</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n  options <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\r\n    <span class=\"token literal-property property\">ignore</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token string\">'#added_at_runtime'</span><span class=\"token punctuation\">,</span> <span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">test\\-[0-9]+</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">media</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\r\n      <span class=\"token string\">'(min-width: 700px) handheld and (orientation: landscape)'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">csspath</span><span class=\"token operator\">:</span> <span class=\"token string\">'../public/css/'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">raw</span><span class=\"token operator\">:</span> <span class=\"token string\">'h1 { color: green }'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">stylesheets</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span>\r\n      <span class=\"token string\">'lib/bootstrap/dist/css/bootstrap.css'</span><span class=\"token punctuation\">,</span>\r\n      <span class=\"token string\">'src/public/css/main.css'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">ignoreSheets</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">[</span><span class=\"token regex\"><span class=\"token regex-delimiter\">/</span><span class=\"token regex-source language-regex\">fonts.googleapis</span><span class=\"token regex-delimiter\">/</span></span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">timeout</span><span class=\"token operator\">:</span> <span class=\"token number\">1000</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">htmlroot</span><span class=\"token operator\">:</span> <span class=\"token string\">'public'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">report</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">banner</span><span class=\"token operator\">:</span> <span class=\"token boolean\">false</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">uncssrc</span><span class=\"token operator\">:</span> <span class=\"token string\">'.uncssrc'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token literal-property property\">userAgent</span><span class=\"token operator\">:</span>\r\n      <span class=\"token string\">'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X)'</span><span class=\"token punctuation\">,</span>\r\n    <span class=\"token function-variable function\">inject</span><span class=\"token operator\">:</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">window</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\r\n      window<span class=\"token punctuation\">.</span>document\r\n        <span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'html'</span><span class=\"token punctuation\">)</span>\r\n        <span class=\"token punctuation\">.</span>classList<span class=\"token punctuation\">.</span><span class=\"token function\">add</span><span class=\"token punctuation\">(</span><span class=\"token string\">'no-csscalc'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'csscalc'</span><span class=\"token punctuation\">)</span>\r\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\r\n  <span class=\"token punctuation\">}</span>\r\n\r\n<span class=\"token function\">uncss</span><span class=\"token punctuation\">(</span>files<span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error<span class=\"token punctuation\">,</span> output</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\r\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>output<span class=\"token punctuation\">)</span>\r\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\r\n\r\n<span class=\"token comment\">/* Look Ma, no options! */</span>\r\n<span class=\"token function\">uncss</span><span class=\"token punctuation\">(</span>files<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error<span class=\"token punctuation\">,</span> output</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\r\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>output<span class=\"token punctuation\">)</span>\r\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span>\r\n\r\n<span class=\"token comment\">/* Specifying raw HTML */</span>\r\n<span class=\"token keyword\">var</span> rawHtml <span class=\"token operator\">=</span> <span class=\"token string\">'...'</span>\r\n\r\n<span class=\"token function\">uncss</span><span class=\"token punctuation\">(</span>rawHtml<span class=\"token punctuation\">,</span> options<span class=\"token punctuation\">,</span> <span class=\"token keyword\">function</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">error<span class=\"token punctuation\">,</span> output</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\r\n  console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>output<span class=\"token punctuation\">)</span>\r\n<span class=\"token punctuation\">}</span><span class=\"token punctuation\">)</span></code><span aria-hidden=\"true\" class=\"line-numbers-rows\" style=\"white-space: normal; width: auto; left: 0;\"><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span><span></span></span></pre></div>\n<p>Or use their build flows which supports Gulp, Grunt and Broccoli (unfortunately no Webpack 😔). For more information about how to setup those tools refer to <a href=\"https://github.com/uncss/uncss\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">their documentation</a>.</p>\n<h2 id=\"comparison\" style=\"position:relative;\"><a href=\"#comparison\" aria-label=\"comparison permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Comparison</h2>\n<p>Now let’s compare these tools and see their pros and cons.</p>\n<h3 id=\"purifycss\" style=\"position:relative;\"><a href=\"#purifycss\" aria-label=\"purifycss permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>PurifyCSS</h3>\n<p>Some people believe the biggest problem with PurifyCSS is lack of modularity. Some think it’s also its biggest benefit 🤷🏽‍♂️. It can work with any file type not just HTML. It can also find selectors which are added using JavaScript.</p>\n<p>Unfortunately since every word is considered a selector, this can end up in a lot of false positives and make the resulting CSS a bit larger than it should be.</p>\n<h3 id=\"purgecss\" style=\"position:relative;\"><a href=\"#purgecss\" aria-label=\"purgecss permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Purgecss</h3>\n<p>Purgecss fixes the above issue by providing the possibility to create an extractor. This is simply a function which takes content of a file and extracts the list of CSS selectors used in it.</p>\n<p>The extractor can be used as a parser that returns an AST (abstract syntax tree) and looks through it to find any CSS selectors. This is the way <code class=\"language-text\">purge-from-html</code> works. You can specify which selectors you want to use for each file type, allowing you to get the most accurate results. Additionally, you can use the default or legacy extractor, which will mimic PurifyCSS’s behaviour.</p>\n<p>That said, Purgecss has some drawbacks too. FIrst and foremost you will need to write a custom extractor for frameworks like <code class=\"language-text\">Tailwind</code>. Another problem is when you use a syntax highlighter like <a href=\"https://prismjs.com/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">primjs</a>, in which case you will have to whitelist your token classes using a property called <code class=\"language-text\">whitelistPatternsChildren</code>.</p>\n<p>Another point to consider is that Purgecss doesn’t have an extractor for JavaScript files. But because of its modularity, developers can create custom extractors for frameworks like <em>Angular</em>, <em>React</em> or <em>Vue</em>.</p>\n<h3 id=\"uncss\" style=\"position:relative;\"><a href=\"#uncss\" aria-label=\"uncss permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>UnCSS</h3>\n<p>Because of its HTML emulation and JavaScript execution, UnCSS is effective at removing unused selectors from web applications. However, its emulation can have a cost in terms of performance and practicality.</p>\n<p>At this point in time, UnCSS is probably the most accurate tool to remove unused CSS if you do not use server-side rendering.</p>\n<h2 id=\"other-tools\" style=\"position:relative;\"><a href=\"#other-tools\" aria-label=\"other tools permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Other tools</h2>\n<p>Here is of other tools you can consider:</p>\n<ul>\n<li><a href=\"https://www.jitbit.com/unusedcss/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">GitBit</a>: an online tool which crawls your root page and stylesheets linked in it.</li>\n<li><a href=\"https://unused-css.com/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">UnusedCSS</a>: another online tool which easily find and removes unused CSS rules</li>\n</ul>\n<h2 id=\"summary\" style=\"position:relative;\"><a href=\"#summary\" aria-label=\"summary permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary</h2>\n<p>Although these tools are really helpful in terms of finding unused CSS, each has its own drawbacks and you will need to be careful to not end up with a broken UI.</p>\n<p>Hope you’ve gained just a tiny bit insight on how to find your unused CSS and deploy them to space 😁👇.</p>\n<blockquote class=\"twitter-tweet\"><p lang=\"en\" dir=\"ltr\">Deploy... to Space?!? 🚀🔥🤯 <a href=\"https://t.co/zb8jNPs5zs\">https://t.co/zb8jNPs5zs</a></p>&mdash; StackBlitz (@stackblitz) <a href=\"https://twitter.com/stackblitz/status/1123816907881242624?ref_src=twsrc%5Etfw\">May 2, 2019</a></blockquote>","timeToRead":7,"frontmatter":{"title":"Knock out your unused CSS","unformattedDate":"2019-05-07T00:00:00.000Z","date":"May 07, 2019","path":"/unused-css/","author":"Yaser Adel Mehraban","tags":["css","webperf","unused"],"thumbnail":{"childImageSharp":{"gatsbyImageData":{"layout":"constrained","placeholder":{"fallback":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAALABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAQBA//EABQBAQAAAAAAAAAAAAAAAAAAAAH/2gAMAwEAAhADEAAAAb7OVCaB/8QAGBABAAMBAAAAAAAAAAAAAAAAAgABERD/2gAIAQEAAQUCbVMraiBt5z//xAAVEQEBAAAAAAAAAAAAAAAAAAABEP/aAAgBAwEBPwEn/8QAFREBAQAAAAAAAAAAAAAAAAAAARD/2gAIAQIBAT8BZ//EABgQAAMBAQAAAAAAAAAAAAAAAAIQESEA/9oACAEBAAY/Ai3B6qx//8QAGhAAAgMBAQAAAAAAAAAAAAAAAREAIUEQMf/aAAgBAQABPyE50tWGJsGOPix9iDOf/9oADAMBAAIAAwAAABCAz//EABYRAQEBAAAAAAAAAAAAAAAAAAEQEf/aAAgBAwEBPxAIuz//xAAWEQEBAQAAAAAAAAAAAAAAAAABERD/2gAIAQIBAT8QQyZ//8QAHRABAQACAgMBAAAAAAAAAAAAAREAITFBUWFxsf/aAAgBAQABPxACoEQxg737/MlgwsTZhXWRTYcmM8neAiR8w4z/2Q=="},"backgroundColor":"transparent","images":{"fallback":{"src":"/static/e9460accffc5bf25ec1f18fea307876f/314d7/css.jpg","srcSet":"/static/e9460accffc5bf25ec1f18fea307876f/314d7/css.jpg 600w","sizes":"(min-width: 600px) 600px, 100vw"},"sources":[{"srcSet":"/static/e9460accffc5bf25ec1f18fea307876f/2c469/css.webp 600w","type":"image/webp","sizes":"(min-width: 600px) 600px, 100vw"}]},"width":600,"height":331}}}}}}]}},"pageContext":{"tag":"unused"}},"staticQueryHashes":[],"slicesMap":{}}