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

Allow rails to serve brotli encoded assets #29753

Closed

Conversation

RyanEdwardHall
Copy link

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.

@rails-bot
Copy link

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.

@swrobel
Copy link
Contributor

swrobel commented Nov 9, 2017

@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.

@RyanEdwardHall
Copy link
Author

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 👍

@schneems
Copy link
Member

schneems commented Nov 9, 2017

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?

@matthewd
Copy link
Member

matthewd commented Nov 9, 2017

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.

@nateberkopec
Copy link
Contributor

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.
@brian-kephart
Copy link
Contributor

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?

@jmreid
Copy link

jmreid commented Mar 18, 2019

I ran some benchmarks for this PR vs master:
https://gist.github.com/jmreid/a2b63e1d013e43ee518f2585d58bbdc1

============================== No Accept-Encoding ==============================

Warming up --------------------------------------
              Master     1.414k i/100ms
      RyanEdwardHall     1.179k i/100ms
Calculating -------------------------------------
              Master     14.969k (±11.7%) i/s -     73.528k in   5.007588s
      RyanEdwardHall     12.686k (±10.3%) i/s -     62.487k in   5.005175s

Comparison:
              Master:    14969.1 i/s
      RyanEdwardHall:    12685.9 i/s - same-ish: difference falls within error


============================= gzip Accept-Encoding =============================

Warming up --------------------------------------
              Master     1.425k i/100ms
      RyanEdwardHall     1.135k i/100ms
Calculating -------------------------------------
              Master     13.699k (±13.2%) i/s -     66.975k in   5.019272s
      RyanEdwardHall     11.261k (±13.1%) i/s -     55.615k in   5.076301s

Comparison:
              Master:    13699.4 i/s
      RyanEdwardHall:    11261.1 i/s - same-ish: difference falls within error


=========================== gzip,br Accept-Encoding ============================

Warming up --------------------------------------
              Master     1.371k i/100ms
      RyanEdwardHall     1.149k i/100ms
Calculating -------------------------------------
              Master     13.812k (±11.3%) i/s -     68.550k in   5.059261s
      RyanEdwardHall     11.238k (±12.6%) i/s -     55.152k in   5.028531s

Comparison:
              Master:    13811.7 i/s
      RyanEdwardHall:    11238.4 i/s - same-ish: difference falls within error

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 /public to users anyway, and would be using a caching CDN for these assets.

@swrobel
Copy link
Contributor

swrobel commented Nov 12, 2019

This would be really great to see this merged now that Webpacker supports brotli

@nateberkopec
Copy link
Contributor

Just to chime back in, Brotli is certainly as, if not more relevant than it was in 2017.

@schneems
Copy link
Member

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?

@jmreid
Copy link

jmreid commented Nov 16, 2019

Browser support is very high:
https://caniuse.com/#search=brotli

image

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.

@rails-bot
Copy link

rails-bot bot commented Feb 14, 2020

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.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Feb 14, 2020
@swrobel
Copy link
Contributor

swrobel commented Feb 14, 2020

@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.

@rails-bot rails-bot bot removed the stale label Feb 14, 2020
@gnclmorais
Copy link

@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).

@nateberkopec
Copy link
Contributor

@gnclmorais

But if you want to compress other file types, or if you want to use a compression algorithm that isn’t gzip , such as brotli , you can compress the files on your own server, and then serve the files by using CloudFront.

^^ That is exactly what this pull request would enable.

@gnclmorais
Copy link

Yes, sorry if I misunderstood @swrobel — I guess I’m adding to the argument and kindly asking for this feature to be considered…! 🙇🏻‍♂️

@jeremy
Copy link
Member

jeremy commented Jun 1, 2020

Merged in #38674. Thanks @RyanEdwardHall!

@jeremy jeremy closed this Jun 1, 2020
@jeremy jeremy added this to the 6.1.0 milestone Jun 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet