Remove unused CSS
Cleaning up your HTML email results in smaller file sizes, which translates to faster email sendouts, faster opens (think slow 3G), and snappier paint times. Gmail will clip your email around 102KB, so anything past that mark won’t even be in the DOM (which can lead to unexpected results like tracking pixel not loaded or, worse, hidden unsubscribe links). You might also want to consider the environmental impact of sending large, unoptimized emails. This Transformer will remove any unused CSS styles and corresponding classes in your HTML, helping you reduce your file size.Usage
Enable it in your Environment config:config.js
Customization
You may configure this Transformer through thecss.purge key in your config.js.
safelist
Array of classes or id’s that you don’t want removed.
config.js
tailwindcss-email-variants plugin for this, so to make sure the plugin works as expected safelist defaults to this:
backend
If you use computed class names, like for example
class="{{ computedRed }} text-sm", the library will normally treat {{ and }} as class names and will remove them.backend option to define the delimiters:
config.js
{{ }} and {% %}.
removeHTMLComments
Set to
false to prevent email-comb from removing <!-- HTML comments -->.config.js
removeCSSComments
Set to
false to prevent email-comb from removing /* CSS comments */.config.js
Preserving CSS comments when inlining
If you have CSS inlining enabled, CSS comments will still be removed, even withremoveCSSComments disabled.
You may use the data-embed attribute on a <style> tag to disable inlining for CSS inside it, if you need to preserve CSS comments.
For example, MailChimp uses CSS comments to define styles that are editable in their email editor. Here’s how you can preserve them:
- Set
removeCSSComments: falsein your config, as above - Write your CSS with comments in a separate
<style>tag:
doNotRemoveHTMLCommentsWhoseOpeningTagContains
HTML email code often includes Outlook or IE conditional comments, which you probably want to preserve. If the opening tag of a conditional includes any of the strings you list here, the Transformer will not remove that comment.
config.js
uglify
Enable this to rename all classes and id’s in both your
<style> tags and your body HTML elements, to be as few characters as possible.config.js
API
The Transformer uses the email-comb library, see all available options here.app.js