In one of my assignments I was trying to render an SVG image. It took me some time to come across one link which states that, in order for IIS express to render an SVG image, you have to include the following code in your web.config file
<staticContent>
<mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
</staticContent>
It worked. But I don't understand why/how? Previously I thought that the server should send the correct Content-Type header. But my svg code was in Javascript. I thought (maybe wrongly) that IIS sends only HTML files to the client side, and those HTML files have the Javascript linked in the header. So, does that mean that IIS is scanning all the javascript files associated with the HTML too? That seems a little hard to believe. If I have 10 javascript files in my HTML main file, and one of them has an SVG file in it, does that mean IIS will scan all of them, and then find out SVG is missing? Is this how it works?
Thanks
MIME types describe the media type of content, either in email, or served by web servers or web applications. They are intended to help provide a hint as to how the content should be processed and displayed. Examples of MIME types: text/html for HTML documents.
If IIS does not recognize the file name extension requested by the client, IIS sends the content as the default MIME type, which is Application. This MIME type signifies that the file contains application data, and it usually means that clients cannot process the file.
Setting the correct MIME data type in the body of the message is critical for both HTTP requests and responses and allows you to control how the request is interpreted by the client and server. Web servers and browsers have a list of well-known file extensions and MIME types.
When your browser hits a URL, it initially only downloads the HTML. For every linked file (Javascript, images, CSS, SVG, etc), the browser will make a separate request to the server. And as you noted, IIS won't serve those files unless it recognizes the MIME type.
To answer your question, no, that's not how it works. IIS doesn't scan the HTML files, it just responds passively to requests from the client (browser). It's the browser that parses the HTML and Javascript, and executes the Javscript, making an additional round-trips back to the server for linked resources as needed.
Edit
The purpose of MIME types for IIS is twofold:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With