BaseX 12 · This is the documentation of an older version. Current version →

Web Serving compressed files in Base13

Sunday, 15 November 2026 · 5 messages · last reply 23 Nov 2026
AB
Andy Bunce15 Nov 2026 14:00 #

Hi,

I recently came across Brotli compression [1] and wondered if it can be used from BaseX 13? The wiki refers to the gzip option [2], which does on the fly compression files to gz where the browser supports it.

BaseX 13.0 ships with Jetty 12.1 and I see compression handling has been revised [3] As I understand it, this can support serving of pre-compressed files including .br (Brotli) just by placing the compressed files adjacent to the expanded files. e.g static/ cm6.js cm6.js.br

Is this feature accessible in BaseX 13?

/Andy

[1] https://en.wikipedia.org/wiki/Brotli [2] https://docs.basex.org/main/Options#gzip [3] https://jetty.org/docs/jetty/12.1/programming-guide/migration/12.0-to-12.1.html#component-changes-compression

CG
Christian Grün16 Nov 2026 10:55 #

Hi Andy,

Files below /static are delivered by our own servlet, which ignores precompressed siblings, and the GZIP option only enables on-the-fly gzip compression. We used to rely on Jetty’s DefaultServlet, but Jetty 12.1 warns when it’s mapped to a sub-path like /static/*, and the recommended replacement (ResourceServlet) cannot be loaded by web applications. A custom servlet also keeps the web.xml independent of Jetty.

It turned out to be easier than expected to support precompressed files with our custom servlet: if a client accepts Brotli or gzip, a sibling file with the suffix .br or .gz (e.g. static/cm6.js.br next to static/cm6.js) is returned instead of the original file, along with the matching Content-Encoding and Vary headers. Brotli is preferred if both files exist.

A new snapshot is online.

Best, Christian

Quoted text · Andy Bunce · 20 lines
Andy Bunce via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Sonntag, 15. November 2026 um 14:01: > Hi, > > I recently came across Brotli compression [1] and wondered if it can be used from BaseX 13? > The wiki refers to the gzip option [2], which does on the fly compression files to gz where the browser supports it. > > BaseX 13.0 ships with Jetty 12.1 and I see compression handling has been revised [3] > As I understand it, this can support serving of pre-compressed files including .br (Brotli) just by placing the compressed files adjacent to the expanded files. > e.g > static/ > cm6.js > cm6.js.br > > Is this feature accessible in BaseX 13? > > /Andy > > [1] https://en.wikipedia.org/wiki/Brotli > [2] https://docs.basex.org/main/Options#gzip > [3] https://jetty.org/docs/jetty/12.1/programming-guide/migration/12.0-to-12.1.html#component-changes-compression
AB
Andy Bunce17 Nov 2026 16:40 #

Thanks. That works for me - 20k sent vs 100k without. See below.

Now I am thinking ... in a WebApp context the best size/performance would be to just have the Brotli file, and for the server to decompress for the rare client does not support it. A small change to the app/static handler and perhaps lib/custom with Brotli4j.jar [1] if the decompression call is too buried in the Jetty jars. ;-)

/Andy

[1] https://github.com/hyperxpro/Brotli4j [image: image.png] Request:

GET /static/htmx.esm.js HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:160.0) Gecko/20100101 Firefox/160.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-GB,en;q=0.9 Accept-Encoding: gzip, deflate, br, zstd DNT: 1 ... Pragma: no-cache Cache-Control: no-cache

Response: HTTP/1.1 200 OK Server: Jetty(12.1.14) Date: Tue, 17 Nov 2026 15:09:36 GMT Vary: Accept-Encoding Content-Type: text/javascript; charset=UTF-8 Content-Encoding: br Last-Modified: Fri, 13 Nov 2026 12:37:13 GMT Content-Length: 20471

Quoted text · Christian Grün · 54 lines
On Mon, 16 Nov 2026 at 09:55, Christian Grün <cg at basex.org> wrote: > Hi Andy, > > Files below `/static` are delivered by our own servlet, which ignores > precompressed siblings, and the GZIP option only enables on-the-fly gzip > compression. We used to rely on Jetty’s DefaultServlet, but Jetty 12.1 > warns when it’s mapped to a sub-path like `/static/*`, and the recommended > replacement (ResourceServlet) cannot be loaded by web applications. A > custom servlet also keeps the web.xml independent of Jetty. > > It turned out to be easier than expected to support precompressed files > with our custom servlet: if a client accepts Brotli or gzip, a sibling file > with the suffix `.br` or `.gz` (e.g. `static/cm6.js.br` next to > `static/cm6.js`) is returned instead of the original file, along with the > matching `Content-Encoding` and `Vary` headers. Brotli is preferred if both > files exist. > > A new snapshot is online. > > Best, > Christian > > > Andy Bunce via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am > Sonntag, 15. November 2026 um 14:01: > > Hi, > > I recently came across Brotli compression [1] and wondered if it can be > used from BaseX 13? > The wiki refers to the gzip option [2], which does on the fly compression > files to gz where the browser supports it. > > BaseX 13.0 ships with Jetty 12.1 and I see compression handling has been > revised [3] > As I understand it, this can support serving of pre-compressed files > including .br (Brotli) just by placing the compressed files adjacent to the > expanded files. > e.g > static/ > cm6.js > cm6.js.br > > Is this feature accessible in BaseX 13? > > /Andy > > [1] https://en.wikipedia.org/wiki/Brotli > [2] https://docs.basex.org/main/Options#gzip > [3] > https://jetty.org/docs/jetty/12.1/programming-guide/migration/12.0-to-12.1.html#component-changes-compression > > >
CG
Christian Grün18 Nov 2026 12:09 #

Hi Andy,

I think we’ll keep the uncompressed file as the reference: dropping it would only save a few KB of disk space, while browsers already get the Brotli file. Decompressing on the fly would would require Brotli4j with native libraries, it would complicate the servlet, and it would be needed more often than expected (e.g. curl and Java’s HttpClient send no Accept-Encoding by default).

Best, Christian

Quoted text · Andy Bunce · 66 lines
Andy Bunce <bunce.andy at gmail.com> schrieb am Dienstag, 17. November 2026 um 16:41: > Thanks. That works for me - 20k sent vs 100k without. See below. > > Now I am thinking ... > in a WebApp context the best size/performance would be to just have the Brotli file, and for the server to decompress for the rare client does not support it. A small change to the `app/static` handler and perhaps lib/custom with Brotli4j.jar [1] if the decompression call is too buried in the Jetty jars. ;-) > > /Andy > > [1] https://github.com/hyperxpro/Brotli4j > [image.png] > Request: > > GET /static/htmx.esm.js HTTP/1.1 > Host: localhost:8080 > User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:160.0) Gecko/20100101 Firefox/160.0 > Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 > Accept-Language: en-GB,en;q=0.9 > Accept-Encoding: gzip, deflate, br, zstd > DNT: 1 > ... > Pragma: no-cache > Cache-Control: no-cache > > Response: > HTTP/1.1 200 OK > Server: Jetty(12.1.14) > Date: Tue, 17 Nov 2026 15:09:36 GMT > Vary: Accept-Encoding > Content-Type: text/javascript; charset=UTF-8 > Content-Encoding: br > Last-Modified: Fri, 13 Nov 2026 12:37:13 GMT > Content-Length: 20471 > > On Mon, 16 Nov 2026 at 09:55, Christian Grün <cg at basex.org> wrote: > >> Hi Andy, >> >> Files below `/static` are delivered by our own servlet, which ignores precompressed siblings, and the GZIP option only enables on-the-fly gzip compression. We used to rely on Jetty’s DefaultServlet, but Jetty 12.1 warns when it’s mapped to a sub-path like `/static/*`, and the recommended replacement (ResourceServlet) cannot be loaded by web applications. A custom servlet also keeps the web.xml independent of Jetty. >> >> It turned out to be easier than expected to support precompressed files with our custom servlet: if a client accepts Brotli or gzip, a sibling file with the suffix `.br` or `.gz` (e.g. `static/cm6.js.br` next to `static/cm6.js`) is returned instead of the original file, along with the matching `Content-Encoding` and `Vary` headers. Brotli is preferred if both files exist. >> >> A new snapshot is online. >> >> Best,Christian >> >> Andy Bunce via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb am Sonntag, 15. November 2026 um 14:01: >> >>> Hi, >>> >>> I recently came across Brotli compression [1] and wondered if it can be used from BaseX 13? >>> The wiki refers to the gzip option [2], which does on the fly compression files to gz where the browser supports it. >>> >>> BaseX 13.0 ships with Jetty 12.1 and I see compression handling has been revised [3] >>> As I understand it, this can support serving of pre-compressed files including .br (Brotli) just by placing the compressed files adjacent to the expanded files. >>> e.g >>> static/ >>> cm6.js >>> cm6.js.br >>> >>> Is this feature accessible in BaseX 13? >>> >>> /Andy >>> >>> [1] https://en.wikipedia.org/wiki/Brotli >>> [2] https://docs.basex.org/main/Options#gzip >>> [3] https://jetty.org/docs/jetty/12.1/programming-guide/migration/12.0-to-12.1.html#component-changes-compression
AB
Andy Bunce23 Nov 2026 14:02 #
Quoted text · Christian Grün · 1 line
>...and it would be needed more often than expected

Good to know. Something like [1] seems to work for what I want.

/Andy [1] https://gist.github.com/apb2006/f955981f0e8d49e6be641ed031d952d8

Quoted text · Christian Grün · 110 lines
On Wed, 18 Nov 2026 at 11:09, Christian Grün <cg at basex.org> wrote: > Hi Andy, > > I think we’ll keep the uncompressed file as the reference: dropping it > would only save a few KB of disk space, while browsers already get the > Brotli file. Decompressing on the fly would would require Brotli4j with > native libraries, it would complicate the servlet, and it would be needed > more often than expected (e.g. curl and Java’s HttpClient send no > Accept-Encoding by default). > > Best, > Christian > ____________________________________ > > Andy Bunce <bunce.andy at gmail.com> schrieb am Dienstag, 17. November 2026 > um 16:41: > > Thanks. That works for me - 20k sent vs 100k without. See below. > > Now I am thinking ... > in a WebApp context the best size/performance would be to just have the > Brotli file, and for the server to decompress for the rare client does not > support it. A small change to the `app/static` handler and perhaps > lib/custom with Brotli4j.jar [1] if the decompression call is too buried in > the Jetty jars. ;-) > > /Andy > > [1] https://github.com/hyperxpro/Brotli4j > [image: image.png] > Request: > > GET /static/htmx.esm.js HTTP/1.1 > Host: localhost:8080 > User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:160.0) > Gecko/20100101 Firefox/160.0 > Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 > Accept-Language: en-GB,en;q=0.9 > Accept-Encoding: gzip, deflate, br, zstd > DNT: 1 > ... > Pragma: no-cache > Cache-Control: no-cache > > Response: > HTTP/1.1 200 OK > Server: Jetty(12.1.14) > Date: Tue, 17 Nov 2026 15:09:36 GMT > Vary: Accept-Encoding > Content-Type: text/javascript; charset=UTF-8 > Content-Encoding: br > Last-Modified: Fri, 13 Nov 2026 12:37:13 GMT > Content-Length: 20471 > > On Mon, 16 Nov 2026 at 09:55, Christian Grün <cg at basex.org> wrote: > >> Hi Andy, >> >> Files below `/static` are delivered by our own servlet, which ignores >> precompressed siblings, and the GZIP option only enables on-the-fly gzip >> compression. We used to rely on Jetty’s DefaultServlet, but Jetty 12.1 >> warns when it’s mapped to a sub-path like `/static/*`, and the recommended >> replacement (ResourceServlet) cannot be loaded by web applications. A >> custom servlet also keeps the web.xml independent of Jetty. >> >> It turned out to be easier than expected to support precompressed files >> with our custom servlet: if a client accepts Brotli or gzip, a sibling file >> with the suffix `.br` or `.gz` (e.g. `static/cm6.js.br` next to >> `static/cm6.js`) is returned instead of the original file, along with the >> matching `Content-Encoding` and `Vary` headers. Brotli is preferred if both >> files exist. >> >> A new snapshot is online. >> >> Best, >> Christian >> >> >> Andy Bunce via BaseX-Talk <basex-talk at mailman.uni-konstanz.de> schrieb >> am Sonntag, 15. November 2026 um 14:01: >> >> Hi, >> >> I recently came across Brotli compression [1] and wondered if it can be >> used from BaseX 13? >> The wiki refers to the gzip option [2], which does on the fly compression >> files to gz where the browser supports it. >> >> BaseX 13.0 ships with Jetty 12.1 and I see compression handling has been >> revised [3] >> As I understand it, this can support serving of pre-compressed files >> including .br (Brotli) just by placing the compressed files adjacent to the >> expanded files. >> e.g >> static/ >> cm6.js >> cm6.js.br >> >> Is this feature accessible in BaseX 13? >> >> /Andy >> >> [1] https://en.wikipedia.org/wiki/Brotli >> [2] https://docs.basex.org/main/Options#gzip >> [3] >> https://jetty.org/docs/jetty/12.1/programming-guide/migration/12.0-to-12.1.html#component-changes-compression >> >> >> >

⚡Generated with XQuery