Asset Packager is in a book! 7

Posted by sbecker Sat, 23 Dec 2006 08:04:00 GMT

My plugin AssetPackager has been featured in Scott Raymond’s new book Ajax on Rails !

Thanks Scott! Everyone go buy a copy. AssetPackager has a full section in Chapter 9 – Performance. Nice.

Comments

Leave a response

  1. Avatar
    michael@schuerig.de Thu, 28 Dec 2006 00:03:44 GMT
    Asset Packager doesn’t behave as expected when :default JavaScript includes are redefined. This can be corrected with a small change.
    1. [‘prototype’, ‘effects’, ‘dragdrop’, ‘controls’] + ActionView::Helpers::AssetTagHelper.send(:class_variable_get, ’@@javascript_default_sources’) + (File.exists?(”#{RAILS_ROOT}/public/javascripts/application.js”) ? [‘application’] : []) + sources[(sources.index(:defaults) + 1)..sources.length] sources.delete(:defaults) end
    sources.collect!{|s| s.to_s}
      sources = (RAILS_ENV == "production" ? 
        AssetPackage.targets_from_sources("javascripts", sources) : 
        AssetPackage.sources_from_targets("javascripts", sources))
    end
    sources.collect {|source| javascript_include_tag(source, options) }.join("\n")
  2. Avatar
    michael@schuerig.de Thu, 28 Dec 2006 00:03:46 GMT
    Asset Packager doesn’t behave as expected when :default JavaScript includes are redefined. This can be corrected with a small change.
    1. [‘prototype’, ‘effects’, ‘dragdrop’, ‘controls’] + ActionView::Helpers::AssetTagHelper.send(:class_variable_get, ’@@javascript_default_sources’) + (File.exists?(”#{RAILS_ROOT}/public/javascripts/application.js”) ? [‘application’] : []) + sources[(sources.index(:defaults) + 1)..sources.length] sources.delete(:defaults) end
    sources.collect!{|s| s.to_s}
      sources = (RAILS_ENV == "production" ? 
        AssetPackage.targets_from_sources("javascripts", sources) : 
        AssetPackage.sources_from_targets("javascripts", sources))
    end
    sources.collect {|source| javascript_include_tag(source, options) }.join("\n")
  3. Avatar
    michael@schuerig.de Thu, 28 Dec 2006 00:05:46 GMT

    Sigh, I trust you’ll be able to figure out what the source code ought to be.

  4. Avatar
    Brett Wed, 24 Jan 2007 06:14:58 GMT
    As I optimize my site further, I want to conditionally include certain javascripts/stylesheets on different pages. What I want is a
    <%= javascript_include_merged @javascripts %>
    

    once in my header partial. Then in any page, I can add the javascripts I need.

    But I needed to add a line to the beginning of javascript_include_merged and stylesheet_link_merged in asset_packager_helper.rb:

    @sources.flatten!@
    
    It works for me.
  5. Avatar
    Brett Wed, 24 Jan 2007 06:54:48 GMT

    That’s

    sources.flatten!
    
  6. Avatar
    Scott Becker Wed, 24 Jan 2007 16:59:55 GMT

    Brett – Instead of modifying the plugin itself, why not do:

    @javascripts.flatten!
    

    in your controller? Asset Packager expects a flattened array of sources already. :)

  7. Avatar
    Brett Sun, 28 Jan 2007 02:55:20 GMT

    Scott, you’re right of course – no need for me to modify the plugin. Just thought it would DRY it up by having it in the plugin. Although it expects a flattened array, forcing a flatten makes it a little more flexible.

    Thanks for a great plugin. It really helps on SSL sites, where assets are not cached.