-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
How to gzip static files? #1237
Comments
It's not currently possible. I'm not 100% sure how it should be done inside Cowboy itself. Outside, you can easily extend cowboy_static or write a stream handler to swap uncompressed with compressed files. |
Thanks. Another solution might be to extend the compress handler and when |
I think adding this feature builtin would be nice. It is good to have official support to enable that. |
I don't disagree this can be useful to many people, but a good solution is complex especially once I add better support for range requests, for example the proposed solution here would not work anymore. I believe if something is to be done it should be done either by modifying the request coming in (rewrite the path and then add the correct content-encoding header in the response) or directly in cowboy_static. |
Even if the websites are fast, web performance scores are always suffering in tools such as http://webpagetest.org or gtmetrix.com etc from now serving compressed files. If it is easy to write a stream handler to swap, would it be possible for you add it (similar as cowboy_compress_h.erl), to swap uncompressed with compressed in the cowboy framework codebase? |
Problem is not so much doing it and including it, but rather doing it in a way that makes all the parts fit well together. Right now it seems there's an increasing need for some sort of rewrite stream handler, and this is only one use case of that would be handler. |
@etxemag75 Some time ago I wrote an alternate static handler that can serve gzipped files. It also supports authentication (which is another feature the current static handler is missing). I don't claim it is perfect, but it works: https://github.com/gotthardp/lorawan-server/blob/master/src/lorawan_admin_static.erl Feel free to adapt it to your needs. |
Shall compression work also for files served by
cowboy_static
? The cowboy_compress_h.erl:98 says We do not compress sendfile bodies. Is this related to whatcowboy_static
does? (Because in my environment REST communication is compressed, but static files are not.) Is there a way to gzip also the static files too?The text was updated successfully, but these errors were encountered: