ring

puzzler 2017-06-28T00:07:09.110356Z

What is recommended for gzip on ring? https://github.com/bertrandk/ring-gzip or https://github.com/amalloy/ring-gzip-middleware or something else?

lumengxi 2017-06-28T01:03:14.586046Z

@puzzler i did a quick look at both of the project and they all look good to me. It is pretty straightforward so I think either one is fine. We have been using the latter in production for almost a year without any problems

puzzler 2017-06-28T04:14:30.973370Z

@lumengxi Thanks!

puzzler 2017-06-28T07:35:35.631892Z

I'd like a little more guidance about how to use the ring-gzip-middleware effectively. Ideally, I'd like to gzip all the javascripts found in the js subdirectory of the resources directory. Problem is that the static resources are configured through site-defaults/wrap-defaults which puts the static file handling in the middle of a huge stack of middleware. It's not really obvious to me how to isolate the js subdirectory for gzip behavior, yet keep all the other options which are vital to good static resource handling. Can anyone point me to a good example?

puzzler 2017-06-28T08:11:51.112884Z

@lumengxi The more I read up on this, the more it looks like a gzip middleware is not advisable unless you have some way of whitelisting or blacklisting certain content types. For example, you never want to gzip pdfs or pngs because those are already compressed and you'll just burn CPU time and make the file bigger. It doesn't look like either of these middleware libs support that out of the box. How are you using the ring-gzip-middleware lib? Are you applying it to everything and if not, how do you discriminate between file types?

puzzler 2017-06-28T08:19:47.224618Z

Upon closer inspection, it looks like ring-gzip has its own reasonable whitelist built in, and there are forks that support static gzip files.

metametadata 2017-06-28T11:05:38.603343Z

@puzzler it's also possible to gzip at the level of the server, e.g. in Jetty: http://martintrojer.github.io/clojure/2015/10/04/enable-gzip-with-ring-and-jetty

puzzler 2017-06-28T12:31:05.736660Z

That's elegant. That may make more sense than to do it at the ring level. I wish immutant had as simple a way to add gzip.

lumengxi 2017-06-28T16:53:59.023043Z

@puzzler we use it only in API services, if your service is serving static contents, I would suggest doing that behind something like nginx, or as @metametadata suggested, in Jetty.