Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are file extensions needed in <img> tags?

Tags:

html

iis

I have a web application that will display logos. Some of the logos will be in GIF format. Some will be in JPEG format.

I'd like to standardize a file naming convention, so that I can find the logo file given the company's Primary Key. For example "British Petroleum" has a PK of 1459, and their logo is stored in /Images/Logos/C1459

So my question is this:

Are the file extensions important? Can I just save the files, and strip off the .JPG or .GIF and expect all browsers to be able to identify and render the file? Or do some broswers rely on the file extension for identification?

I've tried this on a test machine with IE7 and it works fine, but I don't want to assume that all other browsers work the same.

EDIT: A Follow up question. Hows does IIS determine the MIME Type of a extension-less file?

like image 566
Aheho Avatar asked Jun 28 '10 18:06

Aheho


2 Answers

More important to a browser is the MIME type transmitted along with the file during download - historically, some did fall back to heuristics such as file extension or trying to calculate based on the bytes transmitted, but if the MIME type is correct, there would be no need.

like image 61
Rowland Shaw Avatar answered Oct 04 '22 13:10

Rowland Shaw


You'll definitely want to test it in as many browsers as possible, but it should be fine. As long as the file format is correct and the MIME type is being conveyed properly, the browser should merrily display the image just fine. (A lot of sites will have "images" with URLs like: /images/dbimage.aspx?id=123)

Edit: More important to the testing than different browsers, actually, is different image types. If there are any image types that don't get sent with the correct MIME type, you'll want to identify those and either address them or disallow them.

like image 32
David Avatar answered Oct 04 '22 13:10

David