Comments (5)
Thanks, @brenogazzola.
We initially missed this change when migrating from Sprockets to Propshaft and were serving uncompressed assets by default in production with Heroku. Weβre now using Rack::Deflate
and Rack::Brotli::Deflate
to compress responses (without introducing other buildpacks) but wondered if there was a way to restore the build-time compression and let ActionDispatch::Static
serve the best version to clients.
Given it seems cheap to do compression on the fly, I can better see why compression is not considered a responsibility of Propshaft.
from propshaft.
Propshaft delegates to CDNs (or NGINX) the responsibility of compressing files.
NGINX has a cost to do compression since it takes CPU time to do compression on the fly, especially if it's maxed out. This is objectively worse than having your digester compress the files for you beforehand, then you can configure NGINX to say the files are already compressed and serve them as they are without compute time.
Tools like Tailwind and esbuild do not compress files either which leaves performing this action up to the user. That means every user will need to invent their own way to do this and also apply it for every deployment. Would it be fair to say this goes against the grain of what Rails tries to provide? Especially so with Rails pushing hard to use import maps and drop front-end toolchains.
Just throwing this out there to maybe reconsider adding compression support.
from propshaft.
In the Propshaft setup, it is the job of the JavaScript/css bundling tool to generate the compressed version of the assets. Propshaft should copy them, and keep the digest, but I don't think it should compress.
Of course the problem is that in the current implementation, Propshaft modify CSS files to change the image paths, the compressed version would be incorrect.
If we implement compression on Propshaft I don't think there is any feature that Sprockets had that Propshaft doesn't have, so I don't see the point of implementing a new library.
from propshaft.
Thanks, @rafaelfranca.
To ensure I understand:
-
Ideally, it is the responsibility of the JavaScript and CSS bundling tool to generate compressed versions of assets in
app/assets/builds
which Propshaft would then copy and digest appropriately -
However, this would break CSS files that load relative URLs, e.g. background images, as they need their paths updating to the digested version (e.g.
my-image-8ec6a47d28e43287bbe86c88ca83468d728ac84a.jpg
) and Propshaft will not update any compressed CSS files (as they will be opaque.gz
and.br
files rather than.css
which would need decompressing and recompressing)
As for the scope creep of Propshaft vs Sprockets: is there an argument here that this still maintains Propshaft's strict delegation of compiling/bundling assets (viz. you should still use JavaScript and CSS Bundling for Rails to compile your assets with Sass, Tailwind, esbuild, Webpack, etc.) but the compression of copied, digested assets is an acceptable responsibility as it requires knowledge of the final version of the assets, something only Propshaft knows?
from propshaft.
Early versions of Propshaft had brotli compression by default. This was removed when we noticed that CDNs provide this feature on their free plans, and are capable of doing feature detection to decide if they should serve gzip or brotli.
Propshaft delegates to CDNs (or NGINX) the responsibility of compressing files.
from propshaft.
Related Issues (20)
- svg inline display issues HOT 3
- Asset digest is computed before compilation HOT 7
- Not able to detect changes in the assets HOT 1
- Raising an error when an asset is not found HOT 4
- config.asset_host as a proc breaks asset paths HOT 1
- quiet_assets initializer breaks when using a custom Rails logger HOT 2
- Using images inside node_modules HOT 3
- Newly added files that are already digested aren't available in development HOT 4
- `assets:clean` task is not cleaning predigested assets with `.digest` in the name HOT 7
- Allow digested files with the same name prefix
- Upgrade doc refers to 'packages.json' HOT 1
- Current version v0.7.0 contains the broken #118 asset_host handling HOT 1
- Revisit Gzip compression support? HOT 15
- SCSS files digested by default HOT 1
- allow a configurable digest length HOT 11
- Using Propshaft::Asset#content with UTF-8 encoding HOT 5
- Add single files to assets compilation HOT 2
- Digests required in dev? HOT 4
- missing require rack/version causing issues with sidekiq HOT 3
- CSS Variable Images HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from propshaft.