paolochiodi / htmlcompressor

A work in progress port of google's htmlcompressor.jar
Other
152 stars 26 forks source link

NoMethodError (undefined method `compress' for Sass:Module): #24

Closed marvindanig closed 9 years ago

marvindanig commented 9 years ago

I'm getting the following error only on production mode:

Completed 500 Internal Server Error in 15ms (Views: 0.6ms | ActiveRecord: 2.3ms) F, [2015-02-02T10:21:13.342194 #17722] FATAL -- : NoMethodError (undefined method compress' for Sass:Module): htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:555:incompress_css_styles' htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:495:in block in process_style_blocks' htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:494:inmap!' htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:494:in process_style_blocks' htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:476:inprocess_preserved_blocks' htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:202:in compress' htmlcompressor (0.1.2) lib/htmlcompressor/rack.rb:45:incall'

Didn't see this been reported before, but is no one else seeing it?

paolochiodi commented 9 years ago

Are you passing any options to htmlcompressor? My first impression is that you specified an unsupported object as css compressor (any object that has a compress method is supported)

marvindanig commented 9 years ago

I've these options for the htmlcompressor:

 config.middleware.use HtmlCompressor::Rack,
    compress_css: true,
    compress_javascript: true,
    css_compressor: Sass,
    enabled: true,
    javascript_compressor: uglifier,
    preserve_line_breaks: false,
    remove_comments: true,
    remove_form_attributes: false,
    remove_http_protocol: false,
    remove_https_protocol: false,
    remove_input_attributes: true,
    remove_intertag_spaces: false,
    remove_javascript_protocol: true,
    remove_link_attributes: true,
    remove_multi_spaces: true,
    remove_quotes: true,
    remove_script_attributes: true,
    remove_style_attributes: true,
    simple_boolean_attributes: true,
    simple_doctype: false

This has been working normal all this while, until today. And logs didn't show this error before. Which object do you suspect are unsupported and people could easily include?

paolochiodi commented 9 years ago

Here's the problem: Sass is not supported as a css compressor. Not even sure it can be used as a compressor. You could set it to :yui (requires gem yui-compressor) or use something else like cosmic (but may need some additional wrapping)

See here for more infos https://github.com/paolochiodi/htmlcompressor#css-and-javascript-compression

paolochiodi commented 9 years ago

Anyway, chances are that you don't even need css compression in your html files. Do you have lot of <style> tags in them?

marvindanig commented 9 years ago

Just one style tag overall or maximum two on a few specific pages. Interesting that the error never popped up on my actual production server so far. What is Cosmic? Sounds like an interesting name.

Hmm, so the compression of CSS need not be specified 'coz rails is doing it anyway. Let me see if it can be done away with. Thanks Paolo :+1:

paolochiodi commented 9 years ago

The css compression options is to enable compression of css inside <style> directly in your html pages. External stylesheets linked with the <link> are already handled by Rails and Sass.

You probably never seen it in production because you don't have a <style> tag in your pages?

If you need it, check the yui-compressor gem: it will require java to be installed but it's the best option.

paolochiodi commented 9 years ago

Cosmic = ccsmin, damn corrector...

marvindanig commented 9 years ago

:+1: