Socket
Socket
Sign inDemoInstall

csso

Package Overview
Dependencies
8
Maintainers
3
Versions
82
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    csso

CSSO — CSS optimizer


Version published
Weekly downloads
11M
decreased by-21.5%
Maintainers
3
Install size
249 kB
Created
Weekly downloads
 

Package description

What is csso?

CSSO (CSS Optimizer) is a CSS minifier. It performs three kinds of optimizations: structural optimizations, reducing CSS size by merging blocks with identical properties, removing overridden properties, etc.; cleaning (removing unused @media rules, cutting out the comments, etc.); and compressing (transforming values to shorter forms, merging identical selectors, etc.). It can be used as a command-line tool or as a library.

What are csso's main functionalities?

Minification

Minifies CSS by removing whitespace, comments, and making other optimizations to reduce file size.

const csso = require('csso');
const minifiedCss = csso.minify('.test { color: #ff0000; }').css;

Structural Optimization

Optimizes CSS structure by merging blocks with identical properties and removing overridden properties.

const csso = require('csso');
const optimizedCss = csso.minify('.test { color: red; } .test { font-size: 16px; }', { restructure: true }).css;

Source Map Generation

Generates a source map that can be used to debug the minified CSS by mapping it back to the original sources.

const csso = require('csso');
const result = csso.minify('.test { color: red; }', { sourceMap: true });
const minifiedCss = result.css;
const map = result.map.toString();

Other packages similar to csso

Changelog

Source

1.5.0 (January 14, 2016)

Parser

  • attach minus to number

Compressor

  • split code base into small modules and related refactoring
  • introduce internal AST format for compressor (gonzalesinternal and internalgonzales convertors, walkers, translator)
  • various optimizations: no snapshots, using caches and indexes
  • sort selectors, merge selectors in alphabet order
  • compute selector's specificity
  • better ruleset restructuring, improve compression of partially equal blocks
  • better ruleset merge – not only closest but also disjoined by other rulesets when safe
  • join @media with same query
  • outputAst – new option to specify output AST format (gonzales by default for backward compatibility)
  • remove quotes surrounding attribute values in attribute selectors when possible (#73)
  • replace from0% and 100%to at @keyframes (#205)
  • prevent partial merge of rulesets at @keyframes (#80, #197)

API

  • walker for gonzales AST was implemented

CLI

  • new option --stat (output stat in stderr)
  • new optional parameter level for --debug option

Readme

Source

NPM version Build Status Dependency Status devDependency Status

CSSO (CSS Optimizer) is a CSS minimizer unlike others. In addition to usual minification techniques it can perform structural optimization of CSS files, resulting in smaller file size compared to other minifiers.

Install

npm install -g csso

Usage

Command line

csso [input] [output] [options]

Options:

      --debug              Output intermediate state of CSS during compression
  -h, --help               Output usage information
  -i, --input <filename>   Input file
  -o, --output <filename>  Output file (result outputs to stdout if not set)
      --restructure-off    Turns structure minimization off
  -v, --version            Output the version

Some examples:

> csso in.css out.css

> csso in.css
...output result in stdout...

> echo ".test { color: #ff0000; }" | csso
.test{color:red}

> cat source1.css source2.css | csso | gzip -9 -c > production.css.gz

API

var csso = require('csso');

var compressed = csso.minify('.test { color: #ff0000; }');
console.log(compressed);
// .test{color:red}

// you may do it step by step
var ast = csso.parse('.test { color: #ff0000; }');
ast = csso.compress(ast);
var compressed = csso.translate(ast, true);
console.log(compressed);
// .test{color:red}

// There are two options you can pass
var compressedWithOptions = csso.minify('.test { color: #ff0000; }', {
    restructuring: false, // don't combine same selectors
    debug: true // show additional debug information
})

Documentation

May be outdated

FAQs

Last updated on 14 Jan 2016

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc