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

Pre-compress assets #56

Open
theneverstill opened this issue Oct 5, 2018 · 0 comments
Open

Pre-compress assets #56

theneverstill opened this issue Oct 5, 2018 · 0 comments
Labels
enhancement New feature or request MVP2 MVP2 tasks
Projects
Milestone

Comments

@theneverstill
Copy link
Contributor

Prior to upload to S3, we can gzip, brotli, and deflate (and potentially other compressions as well) all assets and upload all of the versions (tack on the compression method as an extension, e.g. image.png.br or image.png.gz). Then, in a pre-cloudfront lambda@edge (yes, this means it is run on EVERY request) we read the Accept-Encoding header and then create a CUSTOM x-compression (or w/e) header with a value of the best compression option the user will accept, tell cloudfront to cache based on our custom header value (and pass it along to the origin), and then in a pre-origin lambda@edge, read that value, and then forward the request to the origin after we update the uri to include the compression extension. (edited)

the lambda@edge pre-origin will only get called when assets of that compression type aren’t cached in cloudfront, but the lambda@edge pre-origin will get called every time. It’ll likely add about 10-20ms to the request and cost $0.60 every million requests, but being able to serve brotli will reduce transfer size by ~20%… so given transfer costs and depending on size of assets, it could end up saving money (and almost guaranteed it’ll reduce transfer times for the user) (edited)
(The pre-cloudfront lambda@edge extra effort is b/c cloudfront strips everything except gzip out of the accept-encoding header. Cloudfront only supports gzip natively. Hopefully one day they’ll stop stripping out the other encoding types and then we could potentially drop that extra lambda.)
Pretty much all evergreen browsers (including mobile) support brotli https://caniuse.com/#feat=brotli

@theneverstill theneverstill added the enhancement New feature or request label Oct 5, 2018
@rpigu-i rpigu-i changed the title Pre-compress assets MVP2 - Pre-compress assets Oct 11, 2018
@grgur grgur added this to Icebox in Capsule Oct 11, 2018
@rpigu-i rpigu-i added the MVP2 MVP2 tasks label Oct 22, 2019
@rpigu-i rpigu-i changed the title MVP2 - Pre-compress assets Pre-compress assets Oct 22, 2019
@rpigu-i rpigu-i added this to the v2 (MVP2) milestone Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request MVP2 MVP2 tasks
Projects
Capsule
  
Icebox
Development

No branches or pull requests

2 participants