paolochiodi / htmlcompressor

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

With this config my site slow down a bit. You can say me why? #32

Closed ghost closed 6 years ago

ghost commented 9 years ago

Hi guys,

If I use this config my site slow down a bit. You can say me why?

I followed this guide: https://remino.net/rails-html-css-js-gzip-compression/

# config/initializers/compression.rb

Rails.application.configure do
  # Use environment names or environment variables:
  # break unless Rails.env.production? 
  break unless ENV['ENABLE_COMPRESSION'] == '1'

  # Strip all comments from JavaScript files, even copyright notices.
  # By doing so, you are legally required to acknowledge
  # the use of the software somewhere in your Web site or app:
  uglifier = Uglifier.new output: { comments: :none }

  # To keep all comments instead or only keep copyright notices (the default):
  # uglifier = Uglifier.new output: { comments: :all }
  # uglifier = Uglifier.new output: { comments: :copyright }

  config.assets.compile = true
  config.assets.debug = false

  config.assets.js_compressor = uglifier
  config.assets.css_compressor = :sass

  config.middleware.use Rack::Deflater
  config.middleware.insert_before ActionDispatch::Static, Rack::Deflater

  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
end
amdstorm commented 8 years ago

You could remove compress_css and javascript_compressor. Rails can compile your css and javascript during asset compilation

paolochiodi commented 8 years ago

@amdstorm compress_css and javascript_compressor compress the javascript and styles inside the page (<script> and <style> tags) and not the external ones linked by the page. Last time I checked Rails does exactly the opposite thing, only compress external files (static assets) and not the one in the html page. Has this changed?

paolochiodi commented 8 years ago

@ginolon sorry for overlooking this issue, but @amdstorm is basically right, the css and javascript compressors may cause a slowdown