Git Product home page Git Product logo

csso-rails's Introduction

csso-rails: Stylesheet Optimizer (CSSO) for Rails Asset pipeline

Gem Version CI Status

Ruby adapter for github.com/css/csso.

CSSO does structure-optimization for CSS. CSS is usually reduced more than in half in uncompressed and around 15% in gzipped.

A Real-World Example

A living rails application CSS – some written in less, some handwritten):

Original sass yui 2.4.7 csso % of original
Plain 129497 107006 60758 60874 47%
GZipped 14046 12047 10558 10472 74%

Very close to yui compressor, wining in gzipped (you’re using nginx mod\_gzip_static, don’t you?)

A more hard example – twitter bootstrap.css, already minified:

Original lessc yui 2.4.7 csso % of original
Plain 81443 71520 68755 67679 83%
GZipped 12384 11633 11652 11477 92%

Please note than benchmark was taken in summer of 2012, since then things may have changed.

Usage

In Rails 3.1+

Add gem 'csso-rails' to your gemfile, and that’s it! (also you may want to add some javascript runtime for ExecJS to pick up, like gem 'therubyracer')

Upon including it becomes the default compressor even if sass is included too. More explicit way – set in config/environment/production.rb:

config.assets.css_compressor = :csso

Sprockets

If you use Sprockets without Rails:

require 'csso'
Csso.install(sprockets_env)

In Plain Ruby

require 'csso'
puts Csso.optimize("a{ color: #FF0000; }") # produces "a{color:red}"

In maniac mode (Csso.optimize(css, true), default for pipeline) CSS is processed several times until it stops getting lighter (there're cases when original csso does not do all optimizations for no reason).

In Command Line

ruby_csso non_optimized.css > optimized.css

MIT-License

Original CSSO code - Copyright (C) 2011 by Sergey Kryzhanovsky.

ruby gem - Copyright(C) 2012 Vasily Fedoseyev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

csso-rails's People

Contributors

ai avatar bobthecow avatar niels avatar sponomarev avatar vasfed avatar yivo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

csso-rails's Issues

Rails 4 support

On Rails 4 raise unknown compressor: csso.

As I understand in Rails 4 we need to register CSS comperssor in Rails app for a instance Sprockets::Environment, like:

initializer "csso.environment", :after => "sprockets.environment" do
  CssCompressor.install(app.assets)
end
class CssCompressor
  def install(sprockets)
    sprockets.register_compressor('text/css', :csso, 'Csso::CssCompressor')
  end
end

After this fix, error doesn’t raise, but CssCompressor#compress didn’t be called. So we need more research (I will research later, after accept another pull request, because it is easy to research on non-Rails Sprockets env).

Sprockets 3.0 compatibity

undefined method `new' for #<Csso::Compressor:0x007fe39f85e3e8>
.bundle/gems/sprockets-3.0.0/lib/sprockets/legacy_tilt_processor.rb:25:in `call'

/cc @Vasfed

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can imagine, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

Csso version

We need csso version in code or README.md to check is csso-rails is actual.

csso v5 upgrade

Can we get this gem updated to support the latest csso v5 library? Thanks.

Still Sprockets 3 issue

NameError: uninitialized constant Sprockets::Compressors
/home/ai/Dev/amplifr/.bundle/gems/csso-rails-0.4.0/lib/csso.rb:16:in `install'
/home/ai/Dev/amplifr/.bundle/gems/csso-rails-0.4.0/lib/csso/railtie.rb:7:in `block in <class:Railtie>'

/cc @Vasfed

therubyracer is not universal

Gem therubyracer is not a only way to execute JS. For example, in some projects we have JRuby, so we can use only therubyrhino.

Will be better to use execjs in dependencies to use any avaiable JS engine.

Easy way to check csso version

Is csso packed in gem latest? Maybe we need some small script to easy pick lastest csso from it repo? Maybe we can use git submodules?

What is a difference between stock csso and packed in your gem?

Unnecessary warning

Hey, I'm using Node.js via ExecJS and it gives me this error.

You're using ExecJS::ExternalRuntime, did you forget to add therubyracer or other execjs runtime to gemfile?

Can we disable the warning since ExecJS will raise an error if no engine is found?

Suggest csso to Sprockets

CSSO is a best compressor. Maybe we should suggest it to Sporockets by default? I will support your issue.

How do I get this working in development?

I'd like to see if this is even working but I can't seem to figure it out. I've followed the installation instructions. I've added therubyracer as well (not sure why this is needed exactly) and have even put...

config.assets.compress = true
config.assets.css_compressor = :csso

...in all of my config/environments, as well as config/application.rb, but I have yet to see it actually compressing anything.

Sorry, I'm a Rails newb but really enjoy CSSO and would love to get this working in tandem with Autoprefixer. :)

Execjs requirement is out of date

Gem::LoadError on line ["1990"] of /Users//.rvm/rubies/ruby-2.0.0-p195/lib/ruby/site_ruby/2.0.0/rubygems/specification.rb: Unable to activate csso-rails-0.3.0, because execjs-2.0.1 conflicts with execjs (> 1.4)
Run with --trace to see the full backtrace

Users that have execjs (2.0.1) throw this error despite both being installed. Can csso-rails be updated to execjs 2.0.1 or is there a way to use either version that may be available?

Missing argument in initialize

I get a fatal error using the csso gem:

screenshot from 2017-07-30 19-38-29

I'm using Rails 3.2 and including csso with:

config.assets.css_compressor = :csso

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.