简体   繁体   中英

css is not cached in cloudfront for rails app?

The following is production.rb

#Production.rb
Rails.application.configure do 
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
  config.assets.compress = true
  config.assets.js_compressor = :uglifier
  config.assets.css_compressor = :sass
  config.assets.compile = true
  config.assets.digest = true
  config.log_level = :debug
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.static_cache_control = "public, max-age=31536000"  
  config.action_controller.asset_host = 'cloudfront url'
end

The Cloudfront deployment is done by separate team. I dont have access to that. Here All the js files are stored in cloudfront cache but the css files are not stored in cloudfront cache.

For all Css files I am getting

 Cache-Control:private
 Connection:keep-alive
 Content-Encoding:gzip
 Content-Length:6845
 Content-Type:text/css; charset=utf-8
 Cteonnt-Length:32061
 Date:Thu, 17 Dec 2015 13:35:27 GMT
ETag:"247788efdf2d42a0c790b271b3d346c626a1b4c3ebbcce792d212937ea5c7b04"
 nnCoection:close
 Status:200 OK
 Via:1.1 f12119dc59597a3cbedac2ac64405829.cloudfront.net (CloudFront)
 X-Amz-Cf-Id:6NCYOH5i738ohaNYHHbc23SkC_HedfU2OIZJBtNEtA_dNpYZtBe4GA==
 X-Cache:Miss from cloudfront
 X-Request-Id:e0d80b13-b5c3-48db-8747-f56dc6e79493
 X-Runtime:0.002792

But for same css in curl it is hitting

 HTTP/1.1 200 OK
 Content-Type: text/css; charset=utf-8
 Content-Length: 122951
 Connection: keep-alive
 Date: Thu, 17 Dec 2015 03:36:06 GMT
 Status: 200 OK
 nnCoection: close
 Cache-Control: public, max-age=31536000
 ETag: "3c489ea49217d1731e0dc838b9453f2319c8b620361eccffa17df67f02ca63f5"
 X-Request-Id: ad9bbcf1-6197-4bed-af86-b9dc2c3a64a7
 X-Runtime: 0.003177
 Age: 30304
 X-Cache: Hit from cloudfront
 Via: 1.1 84da4601f3b7a85ee4beaede1928e823.cloudfront.net (CloudFront)
 X-Amz-Cf-Id: c1CTc_ZKoCtMX4sMe6bA8VcJ0TzliYTkPkqR3EJ1wNu0jKWYBqL49g==

For js files it is hitting. When I make request to css file it is coming from origin(I think) taking too much time.

Any Suggestion?

run this cURL command to verify that the HTTP response Content-Encoding is gzip:

curl -i -H "Accept-Encoding: gzip,deflate" http://your.css.file

You should then see this key phrase in the response

Content-Encoding: gzip

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM