Skip to main content

Minify email code

Use the minify option to trim down the HTML size of your production emails. Minified email code weighs less in KB, resulting in faster sendouts, faster opens, and bandwidth savings on limited mobile data plans. Every little bit helps. Additionally, it reduces the risk of Gmail clipping.

Usage

config.js
export default {
  minify: true,
}

Customization

You may configure the underlying html-crush library:
config.js
export default {
  minify: {
    lineLengthLimit: 500,
  }
}
Checkout the full list of html-crush options.
Minifying email code can lead to unexpected results if not done properly. Make sure you know what you’re doing, and always test your emails!

Options

These are the options that can be passed inside minify:

lineLengthLimit

lineLengthLimit
Number
default:"500"
Maximum line length. Works only when removeLineBreaks is true.
Lines should be no longer than 998 characters, as per RFC 2822.

removeIndentations

removeIndentations
Boolean
default:"true"
By default, code indentation is removed.

removeLineBreaks

removeLineBreaks
Boolean
default:"true"
Should line breaks be removed? Maizzle defaults this option to true.

removeHTMLComments

removeHTMLComments
Boolean|Number
default:"false"
When set to a number, these are the available options:
  • 0 - don’t remove any HTML comments
  • 1 - remove all comments except Outlook conditional comments
  • 2 - remove all comments, including Outlook conditional comments

removeCSSComments

removeCSSComments
Boolean
default:"true"
CSS comments are removed by default, both in <style> tags and in style="" attributes.

breakToTheLeftOf

breakToTheLeftOf
String[]
When any of given strings are encountered and removeLineBreaks is true, current line will be terminated.
Set to false or null or an empty array to disable.

mindTheInlineTags

mindTheInlineTags
String[]
Some inline tags can accidentally introduce extra text. The minifier will take extra precaution when minifying around these tags.
Set to false, null, or an empty array [] to disable.

API

app.js
import { minify } from '@maizzle/framework'

const options = {/* html-crush options */}

const html = await minify('html string', options)

Build docs developers (and LLMs) love