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
Allow rails to serve brotli encoded assets #29753
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
@schneems @matthewd any chance of this making it in? I'm working on the compressed filetype changes we discussed here and I'm wondering if I should keep these changes in mind. |
I would still love to see these changes go in and can find a little time to work on the pull request to accommodate any feedback. Just let me know 👍 |
I'm not opposed to the idea. I'm worried about implementation overhead. Very few people touch action dispatch static or the underlying behavior. @nateberkopec any thoughts? |
The current implementation looks wrong, because (unless I'm misreading) it fails to return a Vary header when the compressed file exists but the current client doesn't accept it. But that's fixable easily enough. (If I'm right about that, it suggests we're already missing a test on that behaviour for gzip.) It's yet another file stat for every [deemed potentially-compressible] response from Static... but maybe the difference from 2 to 3 isn't worth caring so much about. |
I think that's definitely the case here. Brotli has a lot of adoption and will probably become more and more standard over the next 5 years. Most browsers accept it now, it's mostly CDNs that are slow on the uptake. |
When using an external build process (webpack, grunt) it's helpful for rails to be able to serve those assets. Brotli has better compression than gzip and should eventually replace it for static assets. When using an external build process (webpack, grunt) it's helpful for rails to be able to serve those assets. Brotli has better compression than gzip and will eventually replace it for static assets.
b60c5f9
to
b75d3c3
Compare
b75d3c3
to
a8ddfe9
Compare
I've been looking into serving brotli compression and came across this PR. It doesn't appear to have been reviewed since the issue pointed out by @matthewd was fixed. Any chance of it getting a look? |
I ran some benchmarks for this PR vs master:
Looks like it's not that much of an impact on performance. Ideally, most high-traffic apps wouldn't be serving every asset request from |
This would be really great to see this merged now that Webpacker supports brotli |
Just to chime back in, Brotli is certainly as, if not more relevant than it was in 2017. |
Might be worth revisiting. I agree it's more important now. I'm concerned about the performance impact for developers who are not serving brotli files. Do you have any data on what browsers support is like? If all major browsers support it, we should perhaps move sprockets from generating gzip files to brotli by default? |
Browser support is very high: My vote is to get Brotli support into Rails ASAP. In one case for our apps, Brotli would save 750+ KB of JS, 21KB+ of CSS, 150KB+ of SVG (if the whole front-end app was loaded). And a lot of apps have nice smaller wins (like dropping a highly used js file from 85KB to 73KB). On slower cellular connections this ends up being some major savings. |
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@schneems would love to see if there's interest on your end at this point, esp since Heroku is one of the rare situations where one is serving assets directly from the rails server rather than through nginx, where it's easy to configure brotli assets to be served. |
@swrobel, people that use Amazon CloudFront have to compress their own assets and upload them, they don’t support anything besides gzip out of the box (as we can see on their documentation). |
^^ That is exactly what this pull request would enable. |
Yes, sorry if I misunderstood @swrobel — I guess I’m adding to the argument and kindly asking for this feature to be considered…! 🙇🏻♂️ |
Merged in #38674. Thanks @RyanEdwardHall! |
When using an external build process (webpack, grunt) it's helpful for
rails to be able to serve those assets. Brotli has better compression
than gzip and should eventually replace it for static assets.