Zack Burt
Zack Burt

Reputation: 8455

Sometimes (unpredictably) my Rails application serves my assets with a digest. Sometimes, without

Viewing source of my homepage:

  <link data-turbolinks-track="true" href="/assets/application-ea3565aaa6bc4c481fc9425308d6bd54.css" media="all" rel="stylesheet" />
  <script data-turbolinks-track="true" src="/assets/application-2192d37159557835f39e5f3914e03276.js"></script>

Then I refresh...from an "incognito" window:

  <link data-turbolinks-track="true" href="/stylesheets/application.css" media="all" rel="stylesheet" />
  <script data-turbolinks-track="true" src="/javascripts/application.js"></script>

Then I refresh again. It reverts to the original.

As you can imagine, such behavior is quite frustrating.

I'm using Unicorn + nginx. Excerpt from config/environments/production.rb:

  config.cache_classes = true

  # Eager load code on boot. This eager loads most of Rails and
  # your application in memory, allowing both thread web servers
  # and those relying on copy on write to perform better.
  # Rake tasks automatically ignore this option for performance.
  config.eager_load = true

  # Full error reports are disabled and caching is turned on.
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true

  # Disable Rails's static asset server (Apache or nginx will already do this).
  config.serve_static_assets = true

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = :uglifier

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = true

  # Generate digests for assets URLs.
  config.assets.digest = true

Headers for curl that generates assets with digest:

< HTTP/1.1 200 OK
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
< Date: Mon, 27 Apr 2015 12:22:32 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-UA-Compatible: chrome=1
< ETag: "b2c85c1389b561dadeb93132827e948d"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _Foobar_session=EVN3bklLdk9zVE93YllRVVRNY21BejdGRlJJTVUya1JycmlkYUJwSVFjV1lQcmp3em5LQlB1OUlWYk8zRlZlVS8rZTlLQkx4N0MrT1lCUWc4MkgvUTB5YklFUC9XRnJPZTZnTXM0OENPdmtiaWlpTUpOMlRJZUMvb2F4N0dLMEZVZjJDZ1hMdUFHT3k4VzdvMXk4NFJhcE03YysvTUdHUzgvbm5jY0g1UnozaXdtem1SdjYvU25MdFpiL1dqWlVnLS1WbWNHZ3JleHZaWERTbjllVFpFUHVnPT0%3D--1ac9ee1e8f941da47069271998f8cbdec9df68a0; path=/; HttpOnly
< X-Request-Id: 4ff86cd4-229c-4d8b-8f85-71c5f56af0d6
< X-Runtime: 0.016675
< 

No digest:

< HTTP/1.1 200 OK
* Server nginx/1.4.6 (Ubuntu) is not blacklisted
< Server: nginx/1.4.6 (Ubuntu)
< Date: Mon, 27 Apr 2015 12:22:30 GMT
< Content-Type: text/html; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Status: 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-UA-Compatible: chrome=1
< ETag: "141287c98bf53d0894adb5d754bcc2fd"
< Cache-Control: max-age=0, private, must-revalidate
< Set-Cookie: _Foobar_session=XzRrc3BwZHY5dXYyMFRBRFQzTVVTNlZNOEZBbFNQZHdjZ0pSditEenY1YjA1N0h2aW1LeFhJZGdRQVJUZFByaGpaQnYzZkNTallTT0J5TGRmM2Y0ZzVwdjdHT0xabC9YeHk4NzV5TVJFVFk0RmFiVERMRnhwVTIwdDFPTjFFdml0eE1VQ3pSd2lvVGh6czNhT2Q4blZ2cm05K0dNZnhtNnZVOUtSQWdqdnQrSXZGNXcrNlRkYm9VTktnVTRMVmJqLS1saVNldE8zRVdmU3JyK1VqZDdUazN3PT0%3D--276bde7cd6c87d6860a32fac6796fd0ac12bf90b; path=/; HttpOnly
< X-Request-Id: f967633d-2fe5-4705-a6b0-467fb8ce867f
< X-Runtime: 0.019299

Upvotes: 0

Views: 203

Answers (1)

nikolayp
nikolayp

Reputation: 17919

It happens when somewhere a cache was set, thus:

  1. Recheck environment, it should be set to production
  2. Check cache on your headers in app/views/layouts/application.html
  3. Clear directory your_app/public/assets from old cache files on remote server

Then redeploy

Wish it help.

Upvotes: 1

Related Questions