Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make rake assets:precompile:nondigest optional (for applications with…

… fully digested assets)

* Improves speed of precompile significantly.
* Therefore improving speed of deployments OOTB on Heroku etc.
* assets:precompile:nondigest task still runs in Rake and warning issued
* as Rake task still runs, rake task enhancements still possible
* config.assets.nondigest_enabled setting disregarded if not present (backwards compatibility)
  • Loading branch information...
commit d1a8c2e980b569bb13d568bdeecae33cb996eb6d 1 parent 21b69b2
@davidjrice authored
View
6 actionpack/lib/sprockets/assets.rake
@@ -71,7 +71,11 @@ namespace :assets do
end
task :nondigest => ["assets:cache:clean"] do
- internal_precompile(false)
+ if Rails.application.config.assets.nondigest_enabled || Rails.application.config.assets.nondigest_enabled.nil?
+ internal_precompile(false)
+ else
+ warn "Skipping assets:precompile:nondigest set config.assets.nondigest_enabled to true if required"
+ end
end
end
View
2  railties/guides/code/getting_started/config/application.rb
@@ -48,6 +48,8 @@ class Application < Rails::Application
# Enable the asset pipeline.
config.assets.enabled = true
+ # Enable automatic precompilation of nondigest assets
+ config.assets.nondigest_enabled = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
View
2  railties/guides/source/asset_pipeline.textile
@@ -637,6 +637,8 @@ In +application.rb+:
<erb>
# Enable the asset pipeline
config.assets.enabled = true
+# Enable automatic precompilation of nondigest assets
+config.assets.nondigest_enabled = true
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
View
2  railties/guides/source/configuring.textile
@@ -139,6 +139,8 @@ Rails 3.1, by default, is set up to use the +sprockets+ gem to manage assets wit
* +config.assets.enabled+ a flag that controls whether the asset pipeline is enabled. It is explicitly initialized in +config/application.rb+.
+* +config.assets.nondigest_enabled+ a flag that controls whether the automatic precompilation of nondigest asset variants is enabled. It is explicitly initialized and set to true in +config/application.rb+.
+
* +config.assets.compress+ a flag that enables the compression of compiled assets. It is explicitly set to true in +config/production.rb+.
* +config.assets.css_compressor+ defines the CSS compressor to use. It is set by default by +sass-rails+. The unique alternative value at the moment is +:yui+, which uses the +yui-compressor+ gem.
View
2  railties/lib/rails/generators/rails/app/templates/config/application.rb
@@ -64,6 +64,8 @@ class Application < Rails::Application
<% unless options.skip_sprockets? -%>
# Enable the asset pipeline.
config.assets.enabled = true
+ # Enable automatic precompilation of nondigest assets
+ config.assets.nondigest_enabled = true
# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'
View
28 railties/test/application/assets_test.rb
@@ -461,6 +461,34 @@ class ::PostsController < ActionController::Base ; end
assert_equal 0, files.length, "Expected application.js asset to be removed, but still exists"
end
+ test "nondigest assets are not precompiled if config.assets.nondigest_enabled set to false" do
+ app_file "app/assets/application.js", "alert();"
+ add_to_config "config.assets.compile = true"
+ add_to_config "config.assets.digest = true"
+ add_to_config "config.assets.nondigest_enabled = false"
+
+ quietly do
+ Dir.chdir(app_path){ `bundle exec rake assets:clean assets:precompile` }
+ end
+
+ files = Dir["#{app_path}/public/assets/application.js"]
+ assert_equal 0, files.length, "Expected application.js asset not to be generated, but was found"
+ end
+
+ test "nondigest assets are compiled if config.assets.nondigest_enabled not set" do
+ app_file "app/assets/application.js", "alert();"
+ add_to_config "config.assets.compile = true"
+ add_to_config "config.assets.digest = true"
+ add_to_config "config.assets.nondigest_enabled = nil"
+
+ quietly do
+ Dir.chdir(app_path){ `bundle exec rake assets:clean assets:precompile` }
+ end
+
+ files = Dir["#{app_path}/public/assets/application.js"]
+ assert_equal 1, files.length, "Expected application.js asset to be generated, but none found"
+ end
+
test "asset urls should use the request's protocol by default" do
app_with_assets_in_view
add_to_config "config.asset_host = 'example.com'"
Please sign in to comment.
Something went wrong with that request. Please try again.