Bandwidth can be wasted when using verbose plaintext formats such as XML, leading to a poor user experience for your apps. Fortunately, many clients can accept compressed content and Scalatra lets you compress server responses without any change to your business logic. Just mix in GZipSupport.

See scalatra-gzip for a minimal and standalone project containing the example in this guide.


This servlet will reply with compressed content if and only if the client provides an Accept-Header indicating it understands gzip.

class GZipApp extends ScalatraServlet with GZipSupport {

  get("/") {
        <h1>This is
          <a href="">