Я настраиваю приложение Rails на Heroku и сталкиваюсь с проблемой, когда все мои ресурсы CSS загружаются, но ни один из моих активов JS не является. Я использую memcached и следую этим инструкциям: https://devcenter.heroku.com/articles/rack-cache-memcached-rails31.Rails Heroku Предварительно скомпилированные активы не загружаются JS?
Одна вещь, которую я заметил, это то, что когда я изменяю config.assets.compile на «true» в моем файле production.rb, все JS загружаются успешно, но, очевидно, начальная загрузка сайта чрезвычайно медленная. Как устранить эту проблему? Я новичок в Heroku, поэтому я не уверен и не нашел ничего в Интернете, что было бы полезно.
Я предполагаю, что, поскольку все мои JS-файлы находятся в/assets/javascripts /, они должны включаться автоматически, но похоже, что они не являются.
Вот мой production.rb:
BrainDb::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
client = Dalli::Client.new
config.action_dispatch.rack_cache = {
:metastore => client,
:entitystore => client,
:allow_reload => false
}
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
config.static_cache_control = "public, max-age=2592000"
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = false
# Generate digests for assets URLs
config.assets.digest = true
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
end
Я также удалил все из государственных/активов, так что бы прекомпилировать. Вот application.rb:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require(*Rails.groups(:assets => %w(development test)))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end
module BrainDb
class Application < Rails::Application
# Configure the default encoding used in templates for Ruby 1.9.
config.encoding = "utf-8"
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
# Enable escaping HTML in JSON.
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
config.assets.initialize_on_precompile = false
# Enable the asset pipeline
config.assets.enabled = true
config.cache_store = :dalli_store
# Version of your assets, change this if you want to expire all your assets
config.assets.version = '1.0'
конец конец
UPDATE application.js:
//
//= require jquery
//= require jquery_ujs
Вы можете разместить свой файл assets/application.js. Ответ на эту проблему есть. – techvineet
Я обновил его со всем, что находится в файле application.js. Все остальное в верхней части файла - это просто комментарии о том, как использовать файл. –