开发者

Rails - How to write a rendered page as a static HTML file?

The homepage of my application is fairly heavy, it loads content from 6 different web-services on the fly & some of these are quiet slow, most of the data开发者_如何学Go from these service providers & from our own CMS does not change at all during the day - only gets updated late at night.

For performance reasons I would like to write the entire page, which is generated by the /home/index controller/action, to a file in my public directory (/public/home/index.html) so that incoming requests for this page can bypass most of the Rails stack.

Any ideas on how this could be achieved?


You can use the caching system of rails to do that.

Here an example (from this guide):

class ProductsController < ActionController

  caches_page :index

  def index
    @products = Products.all
  end

  def create
    expire_page :action => :index
  end

end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜