Serve Gzipped content with Java Servlets

后端 未结 7 2250
予麋鹿
予麋鹿 2021-01-05 01:40

I was wondering if there was an easy way to serve GZipped content with Java Servlets. I already have the app up and running so the modifications needed should be to

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 02:08

    If you really, really don't want to fiddle with the Java code any more, you could also consider hooking an Apache server in front of your servlet container.

    If you have a lot of static content, this could actually improve performance for you, as the Apache will be a bit faster for static pages than any servlet container. So you'd configure it to only delegate servlet requests to your servlet container on localhost.

    Apache has handy built-in options for compressing output. I don't remember how to set them, but it's easy and versatile. It negotiates with browsers about what they can handle, and so on. In case of doubt, Apache will generally be more savvy and up-to-date on compression methods than any Java container.

提交回复
热议问题