---
title: "rails缓存Tips: 缓存js,css文件"
author: "johnnyhg"
date: "2009-12-26T23:52:58Z"
tags: ["CSS", "Cache", "JavaScript", "Rails"]
categories: ["编程语言"]
slug: "rails-tips-js-css"
draft: false
lastmod: "2009-12-26T23:52:58Z"
id: 557646
url: "https://johnnyhg.iteye.com/blog/557646"
---

4.缓存Tips: 缓存js,css文件

请参考: [http://railslab.newrelic.com/2009/01/22/page-responsiveness](http://railslab.newrelic.com/2009/01/22/page-responsiveness)

```

# Combining all your javascripts in production mode


<%=
 javascript_include_tag
 :all
,
 :cache
 =>
 true
 %>



<%=
 javascript_include_tag
 :all
,
 :cache
 =>
 "main"
 %>



<%=
 javascript_include_tag
 "product"
,
 "cart"
,
 "checkout"
,
 :cache
 =>
 "shop"
 %>


 

# Same sort of stuff with stylesheets


<%=
 stylesheet_link_tag
 :all
,
 :cache
 =>
 true
 %>


 

# Declaring an asset host

ActionController::Base.asset_host = "assets.example.com"

 

# What uses the asset host url


<%=
 image_tag
 'title.gif'
 %>



<%=
 javascript_include_tag
 :all
 %>



<%=
 stylesheet_link_tag
 :all
 %>

```