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

Use zopfli instead of zlib for improved gzip compression on upload #894

Closed
davidmurdoch opened this issue Aug 28, 2018 · 12 comments
Closed

Comments

@davidmurdoch
Copy link

I've forked firebase-tools to do this myselfhere: davidmurdoch@0afb596

Zopfli improves overall file size savings beyond what gzip at level 9 can do at the expense of extra CPU cycles at compression time.

In my branch I just default to using zopfli compression. But it could easily opt-in.

I'm also running with a relatively high number of zopfli iterations that may not be suitable for users with large file sizes. Defaulting to a lower number of iterations or just checking the uncompressed size of the file in order to choose an acceptable number of iterations may be a better choice.

@mbleigh
Copy link
Contributor

mbleigh commented Aug 29, 2018

Thanks for the suggestion! This is something we could consider for the future, but there's a lot to unpack -- we use the content hash of the gzipped file to uniquely identify files, so any change to the gzip compression is going to mean losing the advantages of "change-only" uploads for everyone who switches to the new version.

If the savings are significant, it's still worth considering, but it's not something we can just drop in.

@davidmurdoch
Copy link
Author

Sounds like opt-in would be the way to go then for something like this. The savings are generally pretty minimal (3-8% according to https://developers.googleblog.com/2013/02/compress-data-more-densely-with-zopfli.html), especially considering the upfront CPU cost.

Another potential issue with zopfli is that it uses node-gyp, which can be problematic on Windows builds.

Implementing Brotli in the future would provide much more savings (for browsers that support it), but there would have to be a change to the Firebase back-end to handle it (it used to be possible to serve brotli encoded text-based files from firebase hosting, but a recent serverside change broke this behavior).

@mbleigh
Copy link
Contributor

mbleigh commented Aug 31, 2018

Brotli support is something that's on our radar, but no timeline to announce. node-gyp is definitely a big downside to this, as we've seen tons of problems with it in the past (functions emulation used to depend on grpc, which is a node-gyp library. nothing but pain).

@samtstern
Copy link
Contributor

@Memeriaj this would be a server-side feature right? If so should we close this issue here on firebase-tools since there's nothing that will be done in this repo to address it?

@davidmurdoch
Copy link
Author

davidmurdoch commented Nov 19, 2018

gzipping is currently a client-side feature (or it was when I filed this issue).

@samtstern
Copy link
Contributor

@davidmurdoch oops, I'll show myself out.

@matthewharwood
Copy link

@mbleigh any update on brotli support?

@davidmurdoch
Copy link
Author

@matthewharwood They used to support it by setting a Content-Encoding header
in your firebase.json after brotli encoding the files yourself in a build processes before calling firebase deploy. They broke this back in August and don't plan on fixing it.

They did say back in August that we plan to support brotli in the future (automatically) and only serve the smallest content when possible but I didn't tell me a timeline for when.

@matthewharwood
Copy link

@davidmurdoch yeah heard something like this on Twitter too. Long shot but do you know any cdn that offers brotli without crazy lambda file rewrites on orgin?

@davidmurdoch
Copy link
Author

Cloudflare will do it and it's free. https://support.cloudflare.com/hc/en-us/articles/200168396-What-will-Cloudflare-compress-

@kmcnellis
Copy link
Member

Brotli is available by default on static hosting content now: https://firebase.googleblog.com/2020/08/firebase-hosting-new-features.html

@matthewharwood
Copy link

@kmcnellis Thank you so much for tagging thihs issue. Firebase has always been my favorite static site hosting and now I can finally go back!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants