【问题标题】:rails 3.1 - force development assets to get served up like they were in 3.0.x?rails 3.1 - 强制开发资产像在 3.0.x 中一样提供服务?
【发布时间】:2011-08-30 19:46:40
【问题描述】:

我正在升级应用程序。当前为 3.1.rc8。

问题在于,在开发过程中,对于每个请求,似乎每个资产都会通过 rails 堆栈运行。我们正在谈论每个图像、js 和 css 文件(而且有很多)。在第一次请求之后,它们都返回 304,但仍然如此缓慢。

每次请求后都会有很多这样的内容:

Started GET "/assets/jquery-ui-1.8.16.custom.css?body=1" for 127.0.0.1 at 2011-08-30 15:36:21 -0400
Served asset /jquery-ui-1.8.16.custom.css - 304 Not Modified (0ms)

Started GET "/assets/yui.css?body=1" for 127.0.0.1 at 2011-08-30 15:36:21 -0400
Served asset /yui.css - 304 Not Modified (0ms)

我如何才能使仅在开发中的资产像在 3.0.x 中一样提供服务?

我也在使用这些标签来防止我的 css/js 在 dev 中被编译成单个文件:

= stylesheet_link_tag 'application', :debug => Rails.env.development?
= javascript_include_tag 'application', :debug => Rails.env.development?

这是我的应用程序.rb

require File.expand_path('../boot', __FILE__)

require 'rails/all'

if defined?(Bundler)
  Bundler.require(:default, :assets, Rails.env)
end

module Fooapp
  class Application < Rails::Application
    config.encoding = "utf-8"

    config.filter_parameters += [:password, :password_confirmation]

    config.assets.enabled = true

    config.assets.version = '1.0'
  end
end

和 development.rb:

Fooapp::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 = true

  config.active_support.deprecation = :log

  config.action_dispatch.best_standards_support = :builtin

  config.assets.compress = false

  config.assets.debug = true
end

【问题讨论】:

    标签: ruby-on-rails asset-pipeline


    【解决方案1】:

    Rails 在每个 Sprockets 资产请求上运行所有 to_prepare 钩子 - 并且有很多 gem 在它们的钩子中执行大量工作。 (Rails 本身也是一个间接违规者,因为它也在每次资产请求时重新加载您的一些代码)

    与其等待他们优化他们的预加载钩子(一般来说,或者只是针对资产请求),不如看看https://github.com/wavii/rails-dev-tweaks。它在资产请求期间禁用预加载挂钩(包括代码重新加载)。

    它也可配置为您想要的任何其他请求类型

    【讨论】:

    • 为那颗宝石干杯。很有帮助。
    【解决方案2】:

    我看到的缓慢主要与思考狮身人面像(在我的 Gemfile 中)有关。在开发中,TS 会在每个页面请求上加载一些与 I18n 相关的内容。每个资产都被视为一个页面请求。

    https://github.com/freelancing-god/thinking-sphinx/blob/v2.0.7/lib/thinking_sphinx/railtie.rb#L29

    无论如何,TS 的维护者都知道,该文件不再存在于 master 上。在发布新版本之前,您可以在本地注释掉这两条 I18n 行。

    【讨论】:

      猜你喜欢
      • 2012-01-11
      • 2011-09-27
      • 2011-09-21
      • 2014-03-11
      • 1970-01-01
      • 2011-11-14
      • 1970-01-01
      • 2020-06-10
      • 1970-01-01
      相关资源
      最近更新 更多