简体   繁体   中英

Jetty does not serve static SVGZ files with correct content type

I added the extension svgz to serve compressed svg files, but jetty issues the wrong content encoding. I believe it should be a gzip encoding.

Does anyone know how to configure Jetty to serve static SVGZ files? This is pretty important, as these files are typically very large in size before compression.

Files with extension SVGZ are just SVG files compressed with GZip compression. Rename the file extension, if the file is logo.svgz rename it to logo.svg.gz but keep it compressed.

When compressed SVG files are sent from a Web Server, there are 2 pieces of information that should be in the response headers.

Content-Type: image/svg+xml
Content-Encoding: gzip

Typically, a MIME Type mapping is established in the ${jetty.home}/etc/webdefault.xml file (look for <mime-mapping> ) for the DefaultServlet to use to serve this static file with the appropriate Content-Type, however, this is also compressed, so that means all of the Gzip logic should kick in.

The DefaultServlet will set the appropriate Content-Encoding header if it sees a .gz file extension present for the file requested.

In other words, your http client (browser) can request the file logo.svg , but DefaultServlet will serve from the file contents from logo.svg.gz with Content-Encoding set to gzip.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM