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
精彩评论