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
module.exports = {
minify: true,
}
Customization
You may configure the underlying html-crush
library:
module.exports = {
minify: {
lineLengthLimit: 500,
}
}
Checkout the full list of html-crush options.
Options
These are the options that can be passed inside minify
:
lineLengthLimit
Type: 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
Type: boolean
Default: true
By default, code indentation is removed.
removeLineBreaks
Type: boolean
Default: true
Should line breaks be removed? Maizzle defaults this option to true
.
removeHTMLComments
Type: boolean
or Number
Default: false
When set to a number, these are the available options:
0
- don't remove any HTML comments1
- remove all comments except Outlook conditional comments2
- remove all comments, including Outlook conditional comments
removeCSSComments
Type: boolean
Default: true
CSS comments are removed by default, both in <style>
tags and in style=""
attributes.
breakToTheLeftOf
Type: array
Default: ['</td', '<html', '</html', '<head', '</head', '<meta', '<link', '<table', '<script', '</script', '<!DOCTYPE', '<style', '</style', '<title', '<body', '@media', '</body', '<!--[if', '<!--<![endif', '<![endif]']
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
Type: array
Default: ['a', 'abbr', 'acronym', 'audio', 'b', 'bdi', 'bdo', 'big', 'br', 'button', 'canvas', 'cite', 'code', 'data', 'datalist', 'del', 'dfn', 'em', 'embed', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'map', 'mark', 'meter', 'noscript', 'object', 'output', 'picture', 'progress', 'q', 'ruby', 's', 'samp', 'script', 'select', 'slot', 'small', 'span', 'strong', 'sub', 'sup', 'svg', 'template', 'textarea', 'time', 'u', 'tt', 'var', 'video', 'wbr']
Some inline tags can accidentally introduce extra text. The minifier will take extra precaution when minifying around these tags.
Set to false
or null
or an empty array to disable.
API
const {minify} = require('@maizzle/framework')
const options = {/* html-crush options */}
const html = await minify('html string', options)