Is it possible to serve compressed js in development mode in Rails 3.2? Gemfile contains
gem "closure-compiler"
and development.rb contains
config.serve_static_assets = true
config.assets.compile = false
config.assets.debug = false
config.assets.js_compressor = :closure
config.assets.compress = true
Have runned
RAILS_ENV=development bundle exec rake assets:precompile
And, even though the compiled application.js is there in:
./public/assets/application/application.js
./public/assets/application/application.js.gz
./public/assets/jasmine_rails/application.js
./public/assets/jasmine_rails/application.js.gz
... it never gets served.
This configuration made it work:
config.cache_classes = true
config.whiny_nils = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.assets.compress = true
config.assets.js_compressor = :closure
config.assets.debug = false
config.assets.compile = false
config.assets.digest = true
Related
I use bootstrap-sass to display glyphicons, it works well at localhost under development, but after i deploy it to a server use production, it display as a little square.
I have already search for answers, they just tell me to precompile something. But they didn't work.
This is my production.rb
OperationBackend::Application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.js_compressor = :uglifier
config.assets.compile = false
config.assets.digest = true
config.log_level = :info
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.assets.precompile += ["*.woff", "*.eov", "*.svg", "*.ttf"]
config.log_formatter = ::Logger::Formatter.new
config.active_record.dump_schema_after_migration = false
Paperclip.options[:command_path] = "/usr/local/bin"
end
I also try make config.assets.complie = true
and do RAILS_ENV=production rake asset:precompile but they all didn't work
This problem torture me hours! Wish to got help from you guys!
config.assets.compile = true
should help
This did it for us. The glyphicons are in the vendors folder, so this is what we had to do to get them to work.
For some reason this worked for our production environment, but not our staging. Our staging.rb file is exactly the same as the production.rb file so this is quite the mystery.
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
config.assets.precompile << lambda do |filename, path|
path =~ /vendor\/assets/ && !%w(.js .css).include?(File.extname(filename))
end
I have pushed my rails 4 app to heroku, everythings works fine.
i have created a staging app by forking the original production app and i have named it "staging".
Now i have 2 apps: production and staging.
to have the same configuration I copied
config/environments/production.rb in config/environments/staging.rb .
i have pushed in heroku:
git push staging master
but the problem is in staging app i have no css and no js, but in production app i have both.
this is my production.rb file
#config/environments/production.rb
CentroservizirovigoCom::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
config.assets.digest = true
config.assets.version = '1.0'
config.log_level = :info
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify
config.log_formatter = ::Logger::Formatter.new
end
Can you help me?
Hello i have assets in public directory (because of simplicity)
in layout i load
<link href="/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="/assets/css/jumbotron.css" rel="stylesheet">
<link href="/assets/css/application.css" rel="stylesheet">
and in Development it works well but in Production assets are not loaded.
My Development.rb
Web::Application.configure do
config.cache_classes = false
config.whiny_nils = true
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.action_dispatch.best_standards_support = :builtin
config.active_record.mass_assignment_sanitizer = :strict
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.assets.compress = false
config.assets.debug = true
end
My Production.rb
Web::Application.configure do
config.cache_classes = false
config.consider_all_requests_local = true # default false, zobrazuje errory
config.action_controller.perform_caching = false # default true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true # default false
config.assets.digest = true
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
end
Configuration changed for Rails 4 and 5.
For Rails 4:
config.serve_static_files = true
For Rails 5:
config.public_file_server.enabled = true
This is because you have
config.serve_static_assets = false
in your production.rb file.
From the Rails Configuration guide:
config.serve_static_assets configures Rails itself to serve static assets. Defaults to true, but in the production environment is turned off as the server software (e.g. Nginx or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won´t be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.
And like that guide suggests, you really shouldn't rely on serving assets from public/ via your Rails app, it is better to let the web server (e.g. Apache or Nginx) handle serving assets for performance.
I'm going a little nuts here.
I have 2 servers (heroku, same configuration) in 2 environments (staging, production).
Staging compiles my /assets/templates on demand and caches it without a problem.
Production serves the file uncompiled as html (being haml markup)
The problem is: the configuration of the 2 environments is identical (except mail server)
Gems, environment config and yml are the same.
Any ideas?
Update:
The haml assets where "precompiled" on both servers but raw. Staging didn't get the file missing and re-compiled because assets where compiled for production.
Now I'am stuck with adding haml to the asset compile pipeline with initialize_on_precompile false.
staging.rb / production.rb
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = true
config.static_cache_control = "public, max-age=2592000"
config.assets.compress = true
config.assets.compile = true
config.assets.digest = true
config.assets.precompile += %w( jquery.js modernizr+respond.js polyfills.js )
config.assets.precompile += %w( gp.js ad.js richmarker.js infobox.js )
config.assets.css_compressor = :yui
config.assets.js_compressor = :uglifier
config.assets.compress=true
config.threadsafe! unless $rails_rake_task
config.i18n.fallbacks = true
config.logger = Logger.new(STDOUT)
config.logger.level = Logger.const_get(ENV['LOG_LEVEL'] ? ENV['LOG_LEVEL'].upcase : 'INFO')
config.active_support.deprecation = :notify
config.action_dispatch.rack_cache = {
:metastore => Dalli::Client.new,
:entitystore => 'file:tmp/cache/rack/body',
:allow_reload => false
}
Haml::Template.options[:ugly] = true
Solution was to add the haml into the load. Add the following to application.rb
Sprockets.register_engine '.haml', Tilt::HamlTemplate
I'm trying to compress my CSS and JS files in a Rails 3.1 application, without success.
The files won't get compressed.
Here is my production.rb file.
config.cache_classes = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true
config.assets.js_compressor = :closure
config.assets.css_compressor = :yui
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.assets.digest = true
I've also tried to run rake assets:precompile without success.
Anyone knows what the problem may be?
Found the source to the problem.
I had (for some reason) a manifest file inside the public dir that told the browser to fetch a non compress file.