
Security News
How Enterprise Security Is Adapting to AI-Accelerated Threats
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.
email-minifier
Advanced tools
A well-tested email minifier based on TypeScript for browser and Node.js
EmailMinifier is a well-tested email minifier based on TypeScript for browser and Node.js
https://github.com/luckrnx09/email-minifier/assets/113882203/2f2ad00e-73d8-437e-b357-7505b9d9e78a
As a quick start, you can Try it online 🚀
HTMLMinifier is a great tool for compressing HTML. But email is different from HTML in many ways, compression of HTML is often not the best solution.
You can use the tool you like to install EmailMinifier:
npm
npm install email-minifier
yarn
yarn add email-minifier
pnpm
pnpm install email-minifier
For both browser and Node.js if you use ESM:
import { EmailMinifier } from 'email-minifier';
(async () => {
const emailBody = `<div class="hello"></div>`;
const options = {};
const result = await new EmailMinifier(emailBody).minify(options);
console.log(result);
})();
For Node.js only if you use CommonJS:
const { EmailMinifier } = require('email-minifier');
(async () => {
const emailBody = `<div class="hello"></div>`;
const options = {};
const result = await new EmailMinifier(emailBody).minify(options);
console.log(result);
})();
The minify() method will returns a Promise with the shape as follow:
{
original: '', // the original email body string
minified: '', // minified email body string will be here, if no tasks ran, it'll be null
tasks: [] // all ran tasks when minify email body
}
All available properties for options are as follows
| Option | Description | Default |
|---|---|---|
minifyIds | Minifiy id attributes used in style tags | true |
minifyClasses | Minifiy class attributes used in style tags | true |
minifyDatasets | Minifiy data-* attributes used in style tags | true |
removeUnusedAttrs | Remove custom attributes unused in style tags | false |
minifyStyles | Minifiy CSS content for all the style tags | true |
For removeUnusedAttrs, if you want to remove the specific unused attributes, you can provide an array with RegExp instances to match them.
For example:
const options = {
removeUnusedAttrs: [
new RegExp('custom-test-id') // Remove `custom-test-id` attributes if they not used in style tags
]
};
The following table shows the statistics in the Node.js environment
| Original Size | Minified Size | Elapsed Time | |
|---|---|---|---|
| Holiday Cheer | 33.09kb | 32.36kb | 580.30ms |
| Membership Discount | 104.00kb | 37.97kb | 93.61ms |
| Movies for Christmas | 289.47kb | 58.30kb | 138.13ms |
The emails above are generated from unlayer.
See LICENSE
FAQs
A well-tested email minifier based on TypeScript for browser and Node.js
We found that email-minifier demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.