首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Rails (2.x或3.x)中优化视图性能的提示/技巧?

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

Stack Overflow用户
提问于 2011-05-06 05:41:44
回答 1查看 938关注 0票数 6

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

我们的应用程序将大部分时间用于渲染视图(最少的DB调用)。

我们如何加速视图的性能/渲染?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-06 14:18:31

推荐的加速erb渲染的方法是避免这样做。尝试使用页面缓存或条件GET标头,以避免重新呈现未更改的内容。

http://guides.rubyonrails.org/caching_with_rails.html

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5904415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档