Giter Site home page Giter Site logo

cssmin's Introduction

What is it?

CSSMin takes your CSS file and strips out everything that’s not needed — spaces, extra semicolons, redundant units, and so on. That’s great, but there are loads of programs that do that. A shell script could do that! So what makes CSSMin different?

When you deliver content over the web, best practice is to deliver it gzipped. CSSMin takes your CSS file, and optimises it for gzip compression. This means that there’s a smaller payload delivered over the wire, which results in a faster experience for your users. It does this optimisation by ensuring that the properties inside your selectors are ordered consistently (alphabetically) and in lower case. That way, the gzip algorithm can work at its best.

What this means in practice is that your gzipped CSSMin-ed files are significantly smaller than plain gzipped CSS, and noticeably smaller than files that have been compressed by other means (say, YUI).

What does it do?

  • Replaces font-weight values like 'bold' with their numeric counterparts;
  • Strips quotes wherever possible;
  • Changes as much of the contents to lowercase as possible;
  • Strips all comments from the source;
  • Removes unnecessary whitespace; and, most importantly,
  • Reorders the properties within your selectors alphabetically.

What does it support?

Just about everything! Nested properties benefit from compression (for example, -webkit-keyframes), whilst retaining the appropriate order. Prefixed selectors are moved to the top of the block, so that their non-prefixed counterparts will override them when the browser supports them. Most CSS hacks won't get stripped, but some involving comments might break.

Usage

  1. Compile the library:

     # javac CSSMin.java
    
  2. Run your CSS through it:

     # java CSSMin [input] [output]
    

Results

These are the results of compressing the main CSS file for one of the webapps I develop at work. Note that many of these compressors only offer an online service, which means that they can't easily be used as part of your general build process.

  Original size (bytes) Gzipped size (bytes)
Plain 81938 12291
YUI 64434 10198
LotteryPost 63609 10165
CSS Drive 69275 10795
CSSMin 63791 9896

Contributors

CSSMin was originally written, and is maintained by, Barry van Oudtshoorn. Bug fixes and contributions have been made by Kevin de Groote and Pedro Pinheiro.

More information

Significant updates warrant an update on my website. Read the latest entry.

License

CSSMin is licensed under the BSD License. See LICENSE for details.

cssmin's People

Contributors

alostale avatar barryvan avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.