[Solved] serving svgz files ...
Added by fpcarv over 4 years ago
Hi everyone!
I've tried to display "svgz" images from lighttpd without success.
SVG files are ok, though ...
Do we need to add/change anything at the config file for "svgz" files to display properly?
Thanks for your support,
-Francisco
Replies (4)
RE: serving svgz files ... - Added by gstrauss over 4 years ago
Your system probably does not set a mimetype for .svgz
You can tell lighttpd to override your system settings with mimetype.assign
RE: serving svgz files ... - Added by fpcarv over 4 years ago
I did ...
mimetype.assign = (
".html" => "text/html",
".css" => "text/css",
".js" => "text/javascript",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png",
".svg" => "image/svg+xml",
".svgz" => "image/svg+xml"
)
Firefox says the XML is not well formed ... I guess the browser has no information the svgz is a compressed file ...
Can you please be more specific?
Where, in the config file, do we say that svgz is a compressed svg image?
Thanks!
RE: serving svgz files ... - Added by gstrauss over 4 years ago
On my system, Fedora Linux, /etc/mime.types contains:
image/svg+xml svg svgz
I think you might want to double-check that your svgz is proper. Did you try opening the file locally in Firefox, e.g. via file:///path/to/file.svgz
https://en.wikipedia.org/wiki/Scalable_Vector_Graphics#Compression
If that doesn't work, you can have lighttpd serve the .svg, and can use lighttpd mod_compress to compress the .svg file with gzip and send Content-Encoding: gzip
, but only to browsers which indicate support with Accept-Encoding: gzip
RE: serving svgz files ... - Added by fpcarv over 4 years ago
Hi,
Problem solved!
Thanks for gstrauss tips ;-)
Like has been said above the svgz file format must be present as a mimetype.assign entry inside the lighttpd.conf, or inside /etc/mime.types (fedora, ubuntu), but not in both.
Lighttpd will parse /etc/mime.types to extract the needed mime types.
# not to be used with /etc/mime.types mimetype.assign += ( ".svg" => "image/svg+xml", ".svgz" => "image/svg+xml" )
To display an svgz image the browser needs to know it is receiving an gzip file, even if it hasn't been processed by mod_compress.
The trick is to send an hand-made "Content-Encoding:gzip" header jointly with the svgz file.
For such thing to happen, first add "mod_setenv" to the server.modules.
server.modules += ( "mod_setenv" )
That will allow us to send "cooked" headers when specified conditions are met.
In our case ... trap lighttpd svgz responses to include the Content-Encoding:gzip header:
$HTTP["url"] =~ "svgz" { setenv.add-response-header = ( "Content-Encoding" => "gzip") }
--- All together: ---
server.modules += ( "mod_setenv" ) $HTTP["url"] =~ "svgz" { setenv.add-response-header = ( "Content-Encoding" => "gzip") } # not to be used with /etc/mime.types mimetype.assign += ( ".svg" => "image/svg+xml", ".svgz" => "image/svg+xml" )
Hope it helps!
-Francisco