我正在Heroku上设置我的Rails应用程序,并遇到一个问题,我的所有CSS资产都已加载但我的JS资产都没有。我正在使用memcached,并按照这些说明操作:https://devcenter.heroku.com/articles/rack-cache-memcached-rails31。
我注意到的一件事是,当我在我的production.rb文件中将config.assets.compile更改为“true”时,所有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'
端 端
更新 的application.js:
//
//= require jquery
//= require jquery_ujs
答案 0 :(得分:0)
添加
//= require_tree .
最后和预编译
。