13

I have a Rails 4.2.4 (Ruby 2.2.2) application and I am serving static assets via Cloudfront.

If Cloudfront is serving something you don't want, there are two possibilities:

  • Invalidate the content in Cloudfront or
  • Change the name of the asset served

However, when i change

Rails.application.config.assets.version = '1.0'

to

Rails.application.config.assets.version = '2.0'

(in config/initializers/assets.rb)

and

  • delete all the assets in public/assets

  • run "RAILS_ENV=staging bundle exec rake assets:precompile"

the same file names are generated!

The only way i found to invalidate the digested file of application.scss was to add some dummy content in order to provoke a new md5 checksum.

What am i doing wrong?

Shouldn't a new assets.version change the digested file names?

Best Regards and thanx!

9

As per the comments in the Rails pull request I opened, this is a regression that needs to be fixed: https://github.com/rails/sprockets-rails/issues/240

Update: As sansarp mentions, one of the workarounds listed in that github issue is to use an old version of sprockets:

gem 'sprockets', '< 3.0.0'

Another workaround is to use the asset path as a cache breaker instead:

# config/initializers/assets.rb
Rails.application.config.assets.prefix = "/assets/v1"
2

Using sprockets of previous version could help you to get file names as expected. gem 'sprockets', '< 3.0.0' https://github.com/rails/sprockets

0

If you use capistrano for deployment be sure to set assets_prefix in the deploy.rb file.

set :assets_prefix, "assets/v1"

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.
{"cc_re__cc_re__cc_by_sa_3_0": ["<li class=\"-item\"><a href=\"https://www.facebook.com/officialstackoverflow/\" class=\"-link\">Facebook</a></li>\r\n                    <li class=\"-item\"><a href=\"https://twitter.com/stackoverflow\" class=\"-link\">Twitter</a></li>\r\n                    <li class=\"-item\"><a href=\"https://linkedin.com/company/stack-overflow\" class=\"-link\">LinkedIn</a></li>\r\n                </ul>\r\n\r\n                <p class=\"mt-auto mb24\">\r\nsite design / logo &#169; 2019 Stack Exchange Inc; user contributions licensed under <a href=\"https://creativecommons.org/licenses/by-sa/3.0/\" rel=\"license\">cc by-sa 3.0</a>\r\n                            with <a href=\"https://stackoverflow.blog/2009/06/25/attribution-required/\" rel=\"license\">attribution required</a>.\r\n                    <span id=\"svnrev\">rev&nbsp;2019.2.19.32908</span>\r\n                </p>\r\n            </div>\r\n        </div>\r\n\r\n            </footer>\r\n            <script>StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); })</script>\r\n    <noscript>\r\n        <div id=\"noscript-warning\">Stack Overflow works b"], "copyright__copyright__copyright": ["d. gem 'sprockets', '< 3.0.0' https://github.com/rails/sprockets\n\n0\n\nIf you use capistrano for deployment be sure to set assets_prefix in the deploy.rb file.\n\nset :assets_prefix, \"assets/v1\"\n\nYour Answer\n\nBy clicking \"Post Your Answer\", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.\n\nNot the answer you're looking for? Browse other questions tagged or ask your own question."]}