npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

css-size

v6.0.4

Published

Compare the compressed and uncompressed sizes of a CSS file before and after processing.

Downloads

504

Readme

css-size

Compare the size of a CSS file after processing it to the original.

Deprecation notice: this package will soon cease to be maintained

The functionality can be easily replaced by minifying the file and dividing the minified file size by the unminified file size.

Results are shown for uncompressed as well as when compressed using gzip and brotli. For most users, one of the compressed sizes will best represent what will be served to a client in production. It also provides a better comparison between the minified and the original CSS.

CSS is expected to processed by postcss plugins but can be used with any processing code that returns a promise that resolves to an object with a css property.

Install

With npm do:

npm install css-size --save

Example

var postcss = require('postcss');
var autoprefixer = require('autoprefixer');
var nano = require('cssnano');
var css = 'h1 {\n  color: black;\n}\n';
var nanoOpts = {};
var cssSize = require("css-size");

function process(css, options) {
  return postcss([ autoprefixer, nano(options) ]).process(css);
}


cssSize(css, nanoOpts, process).then(function (results) {
    console.log(results);

/*
  { uncompressed:
     { original: '23 B',
       processed: '14 B',
       difference: '9 B',
       percent: '60.87%' },
    gzip:
     { original: '43 B',
       processed: '34 B',
       difference: '9 B',
       percent: '79.07%' },
    brotli:
     { original: '27 B',
       processed: '16 B',
       difference: '11 B',
       percent: '59.26%' } }
*/

});

cssSize.table(css, nanoOpts, process).then(function (table) {
    console.log(table);

/*
    ┌────────────┬──────────────┬────────┬────────┐
    │            │ Uncompressed │ Gzip   │ Brotli │
    ├────────────┼──────────────┼────────┼────────┤
    │ Original   │ 23 B         │ 43 B   │ 27 B   │
    ├────────────┼──────────────┼────────┼────────┤
    │ Processed  │ 14 B         │ 34 B   │ 16 B   │
    ├────────────┼──────────────┼────────┼────────┤
    │ Difference │ 9 B          │ 9 B    │ 11 B   │
    ├────────────┼──────────────┼────────┼────────┤
    │ Percent    │ 60.87%       │ 79.07% │ 59.26% │
    └────────────┴──────────────┴────────┴────────┘
*/

});

cssSize.numeric(css, nanoOpts, process).then(function (results) {
    console.log(results);
/*
{
  uncompressed: {
    original: 23,
    processed: 14,
    difference: 9,
    percent: 0.6087
  },
  gzip: {
    original: 43,
    processed: 34,
    difference: 9,
    percent: 0.7907
  },
  brotli: {
    original: 27,
    processed: 16,
    difference: 11,
    percent: 0.5926
  }
}
*/
});

API

cssSize(input, options, processor)

Pass input of CSS to receive an object with information about the original & minified sizes (uncompressed, gzipped, and brotli'd), plus difference and percentage results. The options object is passed through to the processor should you wish to compare sizes using different options than the defaults.

cssSize.numeric(input, options, processor)

Exactly like cssSize(...) except the results are returned as numbers instead of preformatted strings. In numeric mode, the percentage value is a fraction (rounded to 4 significant digits), instead of being scaled to 100%.

cssSize.table(input, options, processor)

Use the table method instead to receive the results as a formatted table.

input

Type: string, buffer

options

Type: object

processor

Type: function

The processor accepts as arguments the input and options and returns a Promise that resolves to an object with a css property containing the processed css output.

CLI

See the available options with:

$ css-size --help

Related

  • js-size: Display the size of a JS file.

Contributors

See CONTRIBUTORS.md.

License

MIT © Ben Briggs