Reputation: 1601
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
Upvotes: 5
Views: 2990
Reputation: 102743
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:
Upvotes: 7