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.
Related
I am working on Rails 4.2 & Angular 1.4.8 as the front-end. This is my development.rb file:
Rails.application.configure do
config.cache_classes = false
config.eager_load = false
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.assets.raise_runtime_errors = true
config.action_mailer.delivery_method = :letter_opener_web
config.action_mailer.default_url_options = {host: "localhost:3000"}
config.consider_all_requests_local = false
end
I know that by disabling assets.debug I can really speed this up, but I need to have my assets refreshed when I refresh the page. I am doing full stack so I can't precompile assets all the time.
I recently started using guard with guard-rails - do I have any chance ?
I suspect that compiling all assets every time after file changed.
if you require angularjs libs and other libs in to application.js try to create a separate file for libraries and application
See also: Rails 3.1 is very slow in development-mode because of assets, what to do?
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.
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