Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在Rails(2.x或3.x)中优化视图性能的提示/技巧?_Ruby On Rails_Performance_Ruby On Rails 3_Optimization_View - Fatal编程技术网

Ruby on rails 在Rails(2.x或3.x)中优化视图性能的提示/技巧?

Ruby on rails 在Rails(2.x或3.x)中优化视图性能的提示/技巧?,ruby-on-rails,performance,ruby-on-rails-3,optimization,view,Ruby On Rails,Performance,Ruby On Rails 3,Optimization,View,人们可以做些什么来优化Rails2.x(和3.x)中视图的渲染 我们的应用程序大部分时间用于呈现视图(最少的DB调用) 如何加快视图的性能/渲染 谢谢 建议加快erb渲染的方法是避免这样做。尝试使用页面缓存或条件获取标题,以避免重新呈现未更改的内容 class ProductsController@product.updated_at.utc,:etag=>@product) 做你想做的事| # ... 正常响应处理 结束 结束 #如果请求是新的(即未修改),则不需要执行此操作 #什么都行。默

人们可以做些什么来优化Rails2.x(和3.x)中视图的渲染

我们的应用程序大部分时间用于呈现视图(最少的DB调用)

如何加快视图的性能/渲染


谢谢

建议加快erb渲染的方法是避免这样做。尝试使用页面缓存或条件获取标题,以避免重新呈现未更改的内容

class ProductsController@product.updated_at.utc,:etag=>@product)
做你想做的事|
# ... 正常响应处理
结束
结束
#如果请求是新的(即未修改),则不需要执行此操作
#什么都行。默认渲染将使用参数对此进行检查
#在上一次调用stale时使用?并将自动发送
#:未修改。就这样,你完了。
结束
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