When I add JavaScript files to web pages, I have always done for example like this:
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript">
// Custom script
</script>
But today I discovered in the response headers that JavaScript are actually served as application/javascript
. Why is that? Is both correct? Or should I change one to the other? What's going on here?
Definition of a Content Type. In technical terms, a Content Type is a reusable collection of metadata for a category of content, with its corresponding taxonomies that allows you to manage information in a centralized, reusable way.
The Content-Type header is used to indicate the media type of the resource. The media type is a string sent along with the file indicating the format of the file. For example, for image file its media type will be like image/png or image/jpg, etc. In response, it tells about the type of returned content, to the client.
The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending). In responses, a Content-Type header provides the client with the actual content type of the returned content.
The text content type is used for message content that is primarily in human-readable text character format. The more complex text content types are defined and identified so that an appropriate tool can be used to display more complex body parts.
with HTML5, you can just omit the type attribute completely. All browsers assume a default type of JavaScript.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With