Replies: 1 comment 3 replies
-
Hi Jonathan! I like the idea of emphasizing this in the Deployment section, and adding Some deployments won't use compressed assets. Adding it by default would add overhead to the build time. I'd prefer the user to make that decision, as See the following PR regarding future plans to bring "omakase" to |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So the documentation around deployment does mention compressing assets. And the linked discussion did work well for me for adding output of gzip and brotli compression.
But I think it could make the case more strongly that if you are migrating an existing app, and aren't totally sure what's going on, you probably want to start with .gzip (and sure brotli) output, for compatibility with other standard rails mechanisms. i think an argument could even be made that vite-rails ought to generate with gzip and brotli output for default.
Let me explain what I understand of what's going on in other Rails paths, to make sure we are on the same page.
Sprockets, webpacker, as well as cssbundling-rails sass, and jsbundlingrails-esbuild -- in standard default configurations, they all produce
.gz
variants of any produced assets.If your Rails app itself is delivering assets directly, then the Rails code itself will automatically notice these
.gz
variants, and respond to a request for simple, eg,https://hostname/assets/application-[fingerprint].js
, with a response withcontent-encoding: gzip
and the gzip response. (In cases where client will accept-encoding gzip).This is the case on heroku for instance -- generally with a CDN in front of your Rails app, but it's the Rails app delivering the response. It may also be the case in any other setup that has a CDN in front of Rails app directly providing assets.
Other people with web servers providing assets may already have them configured to notice the presence of the
.gz
variant, and return that with content-encoding gzip too -- that's a standard Rails pattern.Anyone that has any of those setups, everything will work with other standard Rails solutions -- webpacker, sprockets, cssbundling-rails or jsbundling-rails. But will break with vite. I suspect there are some people using vite-rails who don't realize that they are not delivering gzip'd content to their users.
(I noticed when running Lighthouse against my in-progress migration to vite, and comparing to my existing sprockets/webpacker app, to make sure I wasn't introducing any performance regressions -- and noticing this big one!)
I think an argument could be made that vite-rails (at least) should by default install vite with gzip and brotli compression, as the default path, to be turned off if a developer does not want it. This would make it behave consistently with other Rails solutions.
Alternately, I think the language should probably be much stronger in the vite-ruby documentation. That, at least for Rails, if you aren't sure what's going on in your setup, you do want to turn on gzip/brotli compression per the instructions in that discussion, to get consistent behavior with other Rails solutions.
(While other rails solutions don't produce the brotli variant -- I confirmed the Rails app actually will serve a
content-encoding: br
when it's present, already, automatically! So that's nice).Beta Was this translation helpful? Give feedback.
All reactions