Search code examples
htmlcssmime

Is the file extension important when a MIME type is involved? Does this affect other things on a server?


Is the file extension important?

For instance, I have a CSS style sheet. I call it "hi.js", and then link to it with its MIME type as text/CSS. Does this work? Is it "illegal" to do?

Edit: it was just a question jeez, not like I'm actually going to do this


Solution

  • When HTTP is involved, file extensions are more or less meaningless. It is the content type that matters (the one that is sent by the server, not the one you tell the browser to expect using the type attribute).

    However, using misleading file extensions will:

    • Make it harder to configure your server (since you'll have to tell it to send a different content-type for that file)
    • Make anyone who has to maintain your code (including you from 6 months in the future) very unhappy with you