views:

95

answers:

6

Does it matter if i name my pictures "test.jpg" or just "test" for the viewers?

<img src="test.jpg" />
<img src="test" />

Both works in all browsers i know but is there any point in using the right file extension?

+1  A: 

Nope. Only the MIME type in the response matters, and sometimes not even that.

Ignacio Vazquez-Abrams
+7  A: 

No, what matters is the Content-Type header, which gets served in the HTTP response.

Anton Gogolev
+1: but the extension is sometimes used to "guess" the content-type when there are not present in the HTTP response.
Steve Schnepp
+7  A: 

It probably does not matter (see other answers).

Having that said, why NOT keeping the filename extension? It will make your page source much more readable, and you'll easily understand the file types stored at the server.

Even if there are no technical reasons for that, it is a very good practice to keep each file with a meaningful extension. Likewise, I guess you can save your .c, .h. and .py files without extensions. They'll compile and run, but it would just make your life a whole lot harder.

Adam Matan
+1 my thoughts exactly
ILMV
I agree, but right now i have a situation where i will know the format when i store the image but not when i want to display it. Of course i could store the format in a database but if there is no point in doing that i will save some time.
Martin
Does it make it (slightly) more difficult for people to `Save As...`?
Jay
You can write a small script for that, no need to use a DB table. BTW, how does that situation happen?
Adam Matan
+1 for ''a very good practice ... meaningful extension''
Steve Schnepp
@martin: if you know the format at the time you are storing it, you really should save that information. i don't see what time would be saved by not storing it.
Chris Lively
If you don't know the format when you serve it, then serve it from a dynamic url, like this: <img src="getImage.aspx?ImageName=whatever" />
Sam
Martin
@Chris: Development time.@Sam: What would the point of that be? Then noone sees the extension anyway. The only reason to use extensions was to make the html-source more readable.
Martin
@Martin: Exactly how much development time is there in adding a field, and changing an insert / update / select statement? Probably less then the amount of time you've spent asking this question.
Chris Lively
@Chris: Hehe yeah i sort of hoped for a yes/no answer ;D But it's a little bit more complex, i havn't described all special cases of my app. But for other reasons i've now decided to use a db anyway so db it is :)
Martin
+1  A: 

For images it doesn't really matter since they use the mime-type. But the fact that you're asking means that even you think it's slightly confusing. This also assumes some mod_rewrite foo or you're loading the images through your framework which is going to cost you some performance.

Chuck Vose
+4  A: 

In theory, what matters is the Content-Type header, as Anton pointed out.

However, in practice, at least Internet Explorer will in some cases try to "guess" the MIME type, even if it is specified in the Content-Type header. Then the filename is one of the things considered. This should however only apply in some special cases.

See here: http://msdn.microsoft.com/en-us/library/ms775147%28VS.85%29.aspx

sleske
+1  A: 

To the browser, no, the MIME type is what truly matters. See this list of MIME types.

To the user, adding the extension may be meaningful, but most image URLs aren't visible to the end user so this isn't a big point.

To the server, the extension could definitely matter. Most web servers use the extension of a file as the means by which they determine how to handle an incoming request. e.g.:

If you had the need to dynamically generate the robots.txt file you may set up your web server to handle incoming .txt requests differently than if you used a static robots.txt.

Michael Krauklis
In this case i use Amazon S3 to store the files and they don't care about extensions at all so that's not a problem. But good to know in the general case :)
Martin