thumblemonks / smurf

Rails plugin to automatically minify JavaScript and CSS when their bundles get cached
http://gusg.us/code/ruby/smurf-rails-autominifying-js-css-plugin.html
MIT License
193 stars 12 forks source link

Minify fails on already minified javascript #6

Open mperham opened 14 years ago

mperham commented 14 years ago
<%= javascript_include_tag :defaults, :cache => true, :concat => true %>

ActiveSupport.on_load(:action_view) do
  ActiveSupport.on_load(:after_initialize) do
    ActionView::Helpers::AssetTagHelper::register_javascript_expansion :defaults => ['modernizr-1.5.min', 'rails', 'application']
  end
end

Unterminated RegExp Literal
vendor/plugins/smurf/lib/smurf/javascript.rb:164:in `action'
vendor/plugins/smurf/lib/smurf/javascript.rb:221:in `jsmin'
vendor/plugins/smurf/lib/smurf/javascript.rb:51:in `initialize'

The problem is modernizr-1.5.min which has already be minified and apparently your pure-Ruby javascript minifier does not handle part of its syntax. You can find modernizr here:

http://www.modernizr.com/

mperham commented 14 years ago

Was able to work around the problem at runtime:

# lib/smurf/javascript.rb line 47
def initialize(content)
  @input = StringIO.new(content)
  begin
    @output = StringIO.new
    jsmin
  rescue RuntimeError => ex
    puts "Unable to minify Javascript: #{ex.message}"
    @output = StringIO.new(content)
  end
end
gus commented 14 years ago

This stinks for Smurf. Would you be willing to fix Smurf and submit a patch?