【问题标题】:css is not cached in cloudfront for rails app?对于rails应用程序,css没有缓存在云端?
【发布时间】:2016-05-15 21:36:43
【问题描述】:

以下是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

Cloudfront 部署由单独的团队完成。我无权访问。这里所有的js文件都存储在云端缓存中,而css文件没有存储在云端缓存中。

对于我得到的所有 Css 文件

 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

但是对于 curl 中的相同 css,它正在命中

 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==

对于 js 文件,它正在命中。当我向 css 文件发出请求时,它来自原点(我认为)花费了太多时间。

有什么建议吗?

【问题讨论】:

    标签: css ruby-on-rails caching amazon-cloudfront


    【解决方案1】:

    运行此 cURL 命令以验证 HTTP 响应 Content-Encoding 是否为 gzip:

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

    然后您应该会在响应中看到这个关键短语

    Content-Encoding: gzip

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 2013-11-18
      • 1970-01-01
      • 2023-02-22
      • 1970-01-01
      相关资源
      最近更新 更多