Yes. By the HTTP protocol, clause 7.2.1:
“Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource.”
So yes, the response headers should contain Content-Type
header for any response data (called “entity-body” in the protocol, often “file” in common language). If it is omitted, the browser is allowed to make its own wild guesses on the type of data it got. In many contexts, the risk of wrong guesses is negligible, but this not a good excuse for violating the protocol.
Attributes like type=text/css
and type=text/javascript
have not been necessary, except by some formal specifications, or even useful. Even if a server incorrectly sends e.g. CSS data without Content-Type
, browsers will treat the data as CSS if <link rel=stylesheet ...>
was the element that caused the request. It’s the rel
attribute that matters in that case.
Content-Type
header for these files? If you are viewing the response from files served from your browser cache then you probably won't see aContent-Type
header.304 not modified
file. Not exactly the cache, but the content-type is dropped from the header. Disabling the cache, everything appears normal again.