paolochiodi / htmlcompressor Goto Github PK
View Code? Open in Web Editor NEWA work in progress port of google's htmlcompressor.jar
License: Other
A work in progress port of google's htmlcompressor.jar
License: Other
Hi
firstly thanks for the great work and i have used your gem in a production app on heroku
I set it up as per your instructions however when I ran the metrics code under page speed it keeps coming up with the html is not minified?
is there any setting i need to use while adding the middleware? thanks for your help
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
In https://github.com/paolochiodi/htmlcompressor/blob/master/lib/htmlcompressor/compressor.rb, :remove_intertag_spaces => false
but in https://github.com/paolochiodi/htmlcompressor/blob/master/lib/htmlcompressor/rack.rb, :remove_intertag_spaces => true
.
This creates an inconsistency which isn't expected, nor explained in the readme.
The compressed output does not put the last s, thus making the css invalid for the browser
https://gist.github.com/GiboMac/aa5e8c572fbda03970bffad24a482af7 (stupid gist but
it should give you the idea)
With the migration of many sites to https, this aggressive default breaks all outgoing http-links.
I would say this is not a sane default anymore and will break many pages.
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:in
compress_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:in
map!'
htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:494:in process_style_blocks' htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:476:in
process_preserved_blocks'
htmlcompressor (0.1.2) lib/htmlcompressor/compressor.rb:202:in compress' htmlcompressor (0.1.2) lib/htmlcompressor/rack.rb:45:in
call'
Didn't see this been reported before, but is no one else seeing it?
Project depends on YUI version 0.9.6 (technically on any version that is >= 0.9.6 and <0.9.7 ;)). 0.9.6 is three years old and is broken on Windows platform due to popen4 dependency.
Please consider upgrading
Hi paolochiodi,
thanks for your gem.
There are new warnings with ruby 2.2.0:
/Users/dmasur/.rvm/gems/ruby-2.2.0/gems/htmlcompressor-0.1.2/lib/htmlcompressor/compressor.rb:112: warning: duplicated key at line 132 ignored: :javascript_compressor
/Users/dmasur/.rvm/gems/ruby-2.2.0/gems/htmlcompressor-0.1.2/lib/htmlcompressor/compressor.rb:113: warning: duplicated key at line 133 ignored: :css_compressor
the warnings is pretty clear. you declared this twice. I don't know why, maybe for documentation, so i didn't open a pull request.
Can you take a look at it?
My settings are as follows
require 'htmlcompressor'
Rails.application.configure do
# 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,
css_compressor: :sass,
compress_javascript: 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
But I am getting the following error No CSS Compressor. Please set the :css_compressor option
I'm using {:awestruct} and get the following warnings:
/var/lib/gems/1.8/gems/htmlcompressor-0.0.5/lib/htmlcompressor/compressor.rb:80: warning: regexp has invalid interval
/var/lib/gems/1.8/gems/htmlcompressor-0.0.5/lib/htmlcompressor/compressor.rb:80: warning: regexp has }' without escape /var/lib/gems/1.8/gems/htmlcompressor-0.0.5/lib/htmlcompressor/compressor.rb:80: warning: regexp has invalid interval /var/lib/gems/1.8/gems/htmlcompressor-0.0.5/lib/htmlcompressor/compressor.rb:80: warning: regexp has
}' without escape
Line at fault in compressor.rb:
LINE_BREAK_PATTERN = Regexp.new("(?:\p{Blank}(\r?\n)\p{Blank})+")
Escaping the curly brackets certainly removes the warning but I'm not 100% if that's the correct thing to do.
Cheers,
Scott.
Hi there.
I just noticed in an app that is using AngularJS, that middleman-minify-html
(which relies on the htmlcompressor gem) strips some values:
ng-disabled="compareDisabled"
is transformed to ng-disabled
data-ng-disabled="compareDisabled"
is transformed to data-ng-disabled
Seems to me that the simple_boolean_attributes
option, when activated, strips this valid e.g. non-boolean attributes.
Maybe the BOOLEAN_ATTR_PATTERN
is mismatching?
PS: Same applies probably to ng-selected
, ng-checked
and ng-readonly
.
When :simple_boolean_attributes
is set to true, ng-disabled
attribute would be screwed up. For example, consider this code:
<button ng-disabled="bar()">Foo</button>
After compression, it becomes:
<button ng-disabled"bar()">Foo</button>
Thanks.
Following this guide (https://remino.net/rails-html-css-js-gzip-compression/) I got an error:
NameError: uninitialized constant HtmlCompressor
remote: /tmp/build_bae5e5126f5adcb967c7086926599cf4/config/initializers/compression.rb:24:in `block in <top (required)>'
on Heroku.
Rails 4.2.1.
Why?
I have to install your Middleware? A gem?
Folks,
I've used this Gem for around 6 months, and just discovered that it added ~3 seconds to the response time of my server. This is really bad. Please see this as a warning - if you think to try it - make sure you measure your overall response time of the server (whether if it's apache or else). I removed it completely and now the website is really fast.
The right solution should be else. Either doing the compression in a low level language, to add speed, or, better, doing the compression not in real-time. Something like assets pipeline for the views and partials.
In current version, remove_spaces_inside_tags()
is always called and cannot be disabled by option.
And this compression causes corruption in <input>
value.
<!-- before -->
<input value=" value = 5 ">
<!-- after -->
<input value=" value=5 ">
So. at least either of following improvements is necessary:
Is there a way to compress .jst.eco files with this gem automatically? I've been using the gem happily for .html.erb files but js templates cause HTML whitespace issue for inline-block elements.
<ul> <li>Total Shares</li> <li> Other li tag </li> </ul>
seems like all the tags have a leading and trailing space.
When I use in config both HtmlCompressor and Rack::Deflater - I get data stream error:
config.middleware.use HtmlCompressor::Rack
config.middleware.use Rack::Deflater
The pattern is looking for a type attribute of text/style
. However, the common value is text/css
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/style#Attributes
I am using actionpack-page_caching to cache static pages and the htmlcompressor as middleware. When I look at my Rails server's response source code in Chrome DevTools it is compressed but when I look at the source of my Page Cached file it is not compressed.
How would this best be fixed? Thanks.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.