← All postsPerson using CSS JS Minifier on a laptop for a real front-end deploy task

Minify a Stylesheet and Script Safely, and Read the Gzip Number

Shrink CSS, JavaScript or HTML with real parsers, read original, minified and gzip sizes, and avoid breaking code on the way to production.

minify CSSminify JavaScriptgzip sizepage speedfront-end deploydeveloper toolsbrowser tools
4 min readDeveloper & Security Tools

You are handing a small marketing site to a client and the stylesheet still carries every comment, indentation and 0px you typed while building it. You have no build pipeline on this project, just files on a host. CSS JS Minifier gives you a smaller version to paste or download, and tells you the size before and after.

Pick CSS, JavaScript or HTML, paste code or upload a file, and the minified output appears on the right after a short pause. Under it you see the original size, the minified size and the gzip size.

Minify CSS and JavaScript online

Minify CSS and JavaScript online

What a real run looks like

Paste a small card component into the CSS tab: a commented .card rule with background-color: #ffffff, a hover shadow with rgba(0, 0, 0, 0.1), a heading rule with margin-top: 0px, and two blank lines between rules. That input is 313 bytes. The output reads .card{background-color:#fff;border:1px solid #e5e7eb;...} and margin: 0px 0px 16px 0px collapses to margin:0 0 16px. It comes to 218 bytes, which the label shows as 30% smaller.

Look at the gzip figure next. The original compresses to about 216 bytes and the minified one to about 182. Servers usually send text compressed, so the gzip numbers are closer to what a visitor downloads. Minifying still helps, but by 34 bytes rather than 95. The honest summary is that comments and whitespace compress well anyway, so the gain on the wire is smaller than the headline percentage.

For JavaScript, a 212-byte function with a comment, long names and Math.round(total * 100) / 100 becomes 94 bytes: function addTax(n,o){const a=n+n*o/100;return Math.round(100*a)/100}console.log(addTax(89,8));. Local names such as price and ratePercent were shortened, while the top-level function name stayed. In the test I ran, a function exposed on window kept its public name too.

What each mode does

CSS mode uses a CSS optimiser that merges and shortens rules. JavaScript mode compresses the code, shortens local variable and parameter names, and removes dead code and comments. HTML mode collapses whitespace, removes comments, drops redundant attributes and script or style type attributes, shortens the doctype, and minifies inline CSS and JavaScript. Attribute quotes and optional tags are left alone, and conditional comments stay.

Whitespace inside pre and textarea elements is preserved, so a code sample on the page keeps its layout.

Steps in the tool

  1. Choose CSS, JavaScript or HTML with the buttons at the top. The sample text swaps with the mode but never overwrites something you typed.
  2. Paste your code in Input, or use Upload a .css, .js or .html file. The mode is chosen from the extension.
  3. Wait for the Minified box to fill. A percentage appears beside its label.
  4. Read the line under the boxes: Original, minified and gzip sizes in bytes.
  5. Press Copy Output, or Download. The file is named styles.min.css, script.min.js or index.min.html depending on the mode.
  6. Load the result in a browser and click through the page before you replace the live file.

When the output is an error

Invalid code produces a red message with a line and column, for instance an unclosed brace in a stylesheet or an unexpected token in a script. No output appears until the parser can read the input, so fix the spot named. This is a handy side effect: a missing semicolon or bracket you did not know about gets reported before deployment.

Mistakes that cost an evening

  • Overwriting your only copy. Minified code is hard to read and has no source map here, so keep the readable source in version control or a folder and publish the .min file next to it.
  • Assuming a script is safe because it parsed. If other scripts call a function by name, or inline HTML handlers refer to it, check those names still match.
  • Mixing modes. A file with an unusual extension is treated as CSS, so switch the button yourself when you paste a script.
  • Minifying already minified vendor files. Run only your own code through it.
  • Judging success by file size alone. Test a page on a phone-sized window and look for broken layout or console errors.

A quick pre-deploy routine

Keep the working source in a src folder and the minified output in the folder you upload. After each edit, repeat the paste and download, rename nothing by hand, and compare the file dates so you never publish a stale .min file. On the host, open the live page in a private window to bypass cached copies, check the browser console for red errors, and scroll the whole page once. If something looks wrong, swap the readable file back in and compare, which takes a minute when the source is still beside it.

HTML mode deserves the same care on templates. Server-side placeholders inside a template are not real HTML, so minify only the rendered output of a page, not the template that produces it.

Working with the other tools

When you need a fingerprint for cache busting or integrity checking, Hash Generator produces a digest of the file text, and Base64 helps when you inline a tiny asset in CSS as a data URI. Both fit the same deploy checklist in the security tools category.

The tool processes the code in your browser, so a stylesheet with unreleased class names does not go to a server for minification. Your 10 trial usages a day are enough for a stylesheet, a script and a page of HTML.

Which file do you minify most, CSS, JavaScript or whole HTML pages? Tell us on the contact page.

Open CSS & JS MinifierOpen Base64 Encode / DecodeOpen Hash Generator