File tree Expand file tree Collapse file tree 5 files changed +49
-3
lines changed
Expand file tree Collapse file tree 5 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 11master
22------
33
4+ * ` EmberCli::Deploy::File ` serves assets with Rails' ` static_cache_control `
5+ value. [ #403 ]
6+
7+ [ #403 ] : https://github.com/thoughtbot/ember-cli-rails/pull/403
8+
490.7.1
510-----
611
Original file line number Diff line number Diff line change @@ -203,8 +203,22 @@ As long as your [CDN is configured to pull from your Rails application][dns-cdn]
203203
204204### Deployment Strategies
205205
206- By default, EmberCLI-Rails will serve the ` index.html ` file that ` ember build `
207- produces.
206+ By default, EmberCLI-Rails uses a file-based deployment strategy that depends on
207+ the output of ` ember build ` .
208+
209+ Using this deployment strategy, Rails will serve the ` index.html ` file and other
210+ assets that ` ember build ` produces.
211+
212+ These EmberCLI-generated assets are served with the same ` Cache-Control ` headers
213+ as Rails' other static files:
214+
215+ ``` rb
216+ # config/environments/production.rb
217+ Rails .application.configure do
218+ # serve static files with cache headers set to expire in 1 year
219+ config.static_cache_control = " public, max-age=31622400"
220+ end
221+ ```
208222
209223If you need to override this behavior (for instance, if you're using
210224[ ` ember-cli-deploy ` 's "Lightning Fast Deployment"] [ lightning ] strategy in
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def mountable?
1313 end
1414
1515 def to_rack
16- Rack ::File . new ( app . dist_path . to_s )
16+ Rack ::File . new ( app . dist_path . to_s , rack_headers )
1717 end
1818
1919 def index_html
@@ -28,6 +28,12 @@ def index_html
2828
2929 attr_reader :app
3030
31+ def rack_headers
32+ {
33+ "Cache-Control" => Rails . configuration . static_cache_control ,
34+ }
35+ end
36+
3137 def check_for_error_and_raise!
3238 app . check_for_errors!
3339
Original file line number Diff line number Diff line change 77
88module Dummy
99 class Application < Rails ::Application
10+ CACHE_CONTROL_FIVE_MINUTES = "public, max-age=300" . freeze
11+
1012 config . root = File . expand_path ( ".." , __FILE__ ) . freeze
1113 config . eager_load = false
1214
@@ -23,6 +25,8 @@ class Application < Rails::Application
2325 # Print deprecation notices to the stderr.
2426 config . active_support . deprecation = :stderr
2527
28+ config . static_cache_control = CACHE_CONTROL_FIVE_MINUTES
29+
2630 config . secret_token = "SECRET_TOKEN_IS_MIN_30_CHARS_LONG"
2731 config . secret_key_base = "SECRET_KEY_BASE"
2832
Original file line number Diff line number Diff line change 1+ describe "GET assets/my-app.js" do
2+ it "responds with the 'Cache-Control' header from Rails" do
3+ build_ember_cli_assets
4+
5+ get "/assets/my-app.js"
6+
7+ expect ( headers [ "Cache-Control" ] ) . to eq ( cache_for_five_minutes )
8+ end
9+
10+ def build_ember_cli_assets
11+ EmberCli [ "my-app" ] . build
12+ end
13+
14+ def cache_for_five_minutes
15+ Dummy ::Application ::CACHE_CONTROL_FIVE_MINUTES
16+ end
17+ end
You can’t perform that action at this time.
0 commit comments