Can an image in a web browser use any file extension?

What if I rename the image with a custom file extension, will any browsers get confused?

For example..

image.jpg

rename to:

image.xyz

Then in the markup do ..

<img src="image.xyz">

      

The image is still JPEG, but just uses the custom file extension. My tests are passing. Will this pose any potential problems?

+3


source to share


2 answers


Yes it is possible, but you need to configure the MIME type on your server. Browsers don't really care about the extension, but they do care about the MIME type that the server indicates the image should be.



When a MIME type is given, it returns that in the header of the Content-Type

image request response.

+4


source


Browsers completely ignore extensions.



As long as your server is sending the correct header Content-Type

, you're fine.

+3


source







All Articles