6
人们可以怎样优化Rails 2.x(和3.x)中视图的渲染?在Rails(2.x或3.x)中优化视图性能的技巧/诀窍?
我们的应用程序花费大部分时间渲染视图(最小DB调用)。
我们该如何加速性能/渲染视图?
谢谢!
人们可以怎样优化Rails 2.x(和3.x)中视图的渲染?在Rails(2.x或3.x)中优化视图性能的技巧/诀窍?
我们的应用程序花费大部分时间渲染视图(最小DB调用)。
我们该如何加速性能/渲染视图?
谢谢!
加速erb渲染的推荐方法是避免这样做。尝试使用页面缓存或条件GET头来避免重新呈现未更改的内容。
http://guides.rubyonrails.org/caching_with_rails.html
class ProductsController < ApplicationController
def show
@product = Product.find(params[:id])
# If the request is stale according to the given timestamp and etag value
# (i.e. it needs to be processed again) then execute this block
if stale?(:last_modified => @product.updated_at.utc, :etag => @product)
respond_to do |wants|
# ... normal response processing
end
end
# If the request is fresh (i.e. it's not modified) then you don't need to do
# anything. The default render checks for this using the parameters
# used in the previous call to stale? and will automatically send a
# :not_modified. So that's it, you're done.
end