Bug 54095 - [patch] support gzipped versions of static resources by DefaultServlet
Summary: [patch] support gzipped versions of static resources by DefaultServlet
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Catalina (show other bugs)
Version: 8.0.x-trunk
Hardware: All All
: P2 enhancement with 1 vote (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2012-11-03 20:49 UTC by Philippe Marschall
Modified: 2013-10-10 21:25 UTC (History)
0 users

patch that supports gzipped versions of files (9.03 KB, patch)
2012-11-03 20:49 UTC, Philippe Marschall
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Marschall 2012-11-03 20:49:45 UTC
Created attachment 29546 [details]
patch that supports gzipped versions of files

If you want to serve gzipped versions of files you often use a filter, valve or enable compression attribute on the connector. However this is suboptimal for several reasons. Compression has to be done in memory so the whole content has to be loaded into memory, the result is not cached meaning compression has to be done over agin and sendfile can't be used.

The most efficient way to implement gzip serving to generate gzipped versions of the resources at build time. Then use a custom filter that forwards to the gzipped version if the user agent supports it. This way sendfile can be used and compression is only done once at build time.

It would be nice if the DefaultServlet detected that there's a gzipped version of the resource and serves it when the client supports it. The Jetty DefaultServlet does exactly this:


Patch attached with tests and updated documentation.
Comment 1 Mark Thomas 2013-10-10 21:25:23 UTC
Thanks for the feature suggestion and the patch. This has been added to 8.0.x and will be included in 8.0.0-RC4 onwards.