Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve serving of prehashed assets #717

Merged
merged 1 commit into from
Sep 17, 2021

Conversation

theodorton
Copy link
Contributor

See rails/jsbundling-rails#21 and rails/jsbundling-rails#15 for motivation. Also builds on the work in #714.

Given an already digested asset chunk-9ad2e0aa4f0e481dfc8eaa4dc850eab8.js, we want to make sure that Sprockets can serve this file.

There are currently two problems that needs to be resolved:

  1. Sprockets::Server will currently try to lookup chunk.js when accessing chunk-9ad2e0aa4f0e481dfc8eaa4dc850eab8.js
  2. Sprockets::Server expects ETags of assets and digests to be the same, but that cannot be predicted as the hashing algorithm and version configured in the Rails application will not match whatever configuration the upstream build process used to digest the file.
  • Sprockets::Server is now changed so that if it fails to find chunk.js, it will instead try and load chunk-9ad2e0aa4f0e481dfc8eaa4dc850eab8.js.
  • When this code path is triggered, the fingerprint will be hijacked and replaced by Asset#etag so the ETag header behavior is consistent with other assets served by sprockets.

@brenogazzola
Copy link
Contributor

Yeah. Adding a fallback behavior does look much better than trying to stop sprockets from removing the fingerprint and should work for solving ou development problem. Does this work too with the assets precompiled?

@theodorton
Copy link
Contributor Author

Does this work too with the assets precompiled?

Yes, it should work for both the development and production scenario.

@dhh dhh merged commit 56b9686 into rails:master Sep 17, 2021
@theodorton theodorton deleted the no-digest-removal-development branch September 17, 2021 13:15
@theodorton theodorton restored the no-digest-removal-development branch September 17, 2021 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants