Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I explicitly specify a MIME type in an img tag

I am trying to display a favicon.ico on a web page not as the shortcut icon, but as an image in the page's body. On our test server in IE, the images were failing to display, and we found out it was because the MIME-type configured on the server for the .ico file type was image/vnd.microsoft.icon instead of image/x-icon.

Now, we were able to reconfigure our server and fix the problem, but I was wondering if it is possible to specify which MIME type to use in the <img> tag and override server-wide settings for a specific file?

like image 772
Martin Avatar asked Apr 16 '14 16:04

Martin


1 Answers

There is no attribute for specifying a media type in an img element. If you use e.g. the object element instead (it works for images, too, but with some quirks), you can use the type attribute there. But its definition in HTML 4.01 says: “This attribute is optional but recommended when data is specified since it allows the user agent to avoid loading information for unsupported content types. If the value of this attribute differs from the HTTP Content-Type returned by the server when the object is retrieved, the HTTP Content-Type takes precedence.” In HTML5 CR, it’s a bit different, but the point still is that the type attribute is not expected to override HTTP headers—quite the contrary.

like image 105
Jukka K. Korpela Avatar answered Oct 30 '22 00:10

Jukka K. Korpela