1

Apache is serving an .svg file, but the HTTP response does not have a Content-type header. Consequently, Chrome is displaying the text of the .svg file, rather than the desired image.

My goal is for Apache to serve the .svg file with the header Content-type: image/svg+xml so that Chrome will display the image.

Aside: The .svg file originally came from here:
https://s3-us-west-2.amazonaws.com/s.cdpn.io/106114/bee.svg

My Apache configuration file is intentionally as small as possible. It is:

DocumentRoot            /path/to/docroot
ErrorLog                /tmp/apache.log
PidFile                 /tmp/apache.pid
Listen                  0.0.0.0:8000
ServerName              127.0.0.1

LoadModule  mpm_prefork_module  /usr/lib/apache2/modules/mod_mpm_prefork.so
LoadModule  authz_core_module   /usr/lib/apache2/modules/mod_authz_core.so

LoadModule  mime_module         /usr/lib/apache2/modules/mod_mime.so
TypesConfig             /etc/mime.types
AddType                 image/svg+xml  .svg

I am running Apache as provided by Ubuntu 20.04 (version 2.4.41-4ubuntu3).

My question is, what configuration changes will cause Apache to provide the desired Content-type header for the .svg file?

0

So I have, I think, tracked down the problem.

Initially, Chrome cached the .svg content without a Content-type.

I then changed Apache's configuration to set Content-type: image/svg+xml.

I then reloaded the image in Chrome. Chrome sends a GET request, but with some cache related headers (for example, one such header is If-Modified-Since).

Apache responds with a 304 Not Modified status. According to Chrome Developer Tools, this response does not include a Content-type header. If the Developer Tools is correct, then Chrome would be unaware that the Content-type has changed.

If I touch the .svg file, or if I clear Chrome's cache, then the image will reload and will be displayed as an image.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.