Gathering detailed insights and metrics for @hint/hint-content-type
Gathering detailed insights and metrics for @hint/hint-content-type
Gathering detailed insights and metrics for @hint/hint-content-type
Gathering detailed insights and metrics for @hint/hint-content-type
npm install @hint/hint-content-type
Typescript
Module System
Node Version
NPM Version
Dist files
Updated on Oct 01, 2019
configuration-development-v6.1.1
Updated on Mar 07, 2019
hint-sri-v3.0.5
Updated on Mar 07, 2019
hint-no-vulnerable-javascript-libraries-v2.7.0
Updated on Mar 07, 2019
hint-css-prefix-order-v1.0.2
Updated on Mar 07, 2019
hint-amp-validator-v2.7.0
Updated on Mar 07, 2019
TypeScript (91.49%)
JavaScript (4.96%)
CSS (2.22%)
Handlebars (0.76%)
EJS (0.5%)
HTML (0.06%)
Batchfile (0.01%)
Shell (0.01%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
Apache-2.0 License
3,653 Stars
6,372 Commits
743 Forks
75 Watchers
157 Branches
105 Contributors
Updated on Jul 11, 2025
Latest Version
4.2.27
Package Id
@hint/hint-content-type@4.2.27
Unpacked Size
39.92 kB
Size
11.92 kB
File Count
13
NPM Version
10.5.0
Node Version
18.19.1
Published on
Aug 29, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
7
1
Content-Type
header (content-type
)content-type
warns against not serving resources with the
Content-Type
HTTP response header with a value containing
the appropriate media type and charset for the response.
Even though browsers sometimes ignore the value of
the Content-Type
header and try to sniff the content (see also: X-Content-Type-Options
hint),
it’s indicated to always send the appropriate media type and
charset for the response as, among other:
the media type defines both the data format and how that data is intended to be processed by browsers
not sending the appropriate charset
, where appropriate, may
prevent things from being rendered correctly
thus creating a bad user experience (see also:
meta-charset-utf-8
hint)
javascript resources served with the wrong media type may be blocked
The hint checks if responses include the Content-Type
HTTP response
header and its value contains the appropriate media type and charset
for the response.
application/javascript
This hint recommends using a Content-Type
of text/javascript
for
JavaScript resources as noted in the HTML standard.
However this hint also allows application/javascript
because that
value was previously recommended by the IETF in RFC 4329.
RFC 4329 has an active draft proposed to also
recommend text/javascript
in the future.
See the section
Can the hint be configured below for an
example of how to require a specific Content-Type
value for
JavaScript resources if desired.
Content-Type
response header is not sent:
1HTTP/... 200 OK 2 3...
Content-Type
response header is sent with an invalid value:
1HTTP/... 200 OK 2 3... 4Content-Type: invalid
1HTTP/... 200 OK 2 3... 4Content-Type: text/html;;;
Content-Type
response header is sent with the wrong media type:
For /example.png
1HTTP/... 200 OK 2 3... 4Content-Type: font/woff2
Content-Type
response header is sent with an unofficial media type:
For /example.js
1HTTP/... 200 OK 2 3... 4Content-Type: application/x-javascript; charset=utf-8
Content-Type
response header is sent without the charset
parameter
for response that should have it:
For /example.html
1HTTP/... 200 OK 2 3... 4Content-Type: text/html
For /example.png
1HTTP/... 200 OK 2 3... 4Content-Type: image/png
For /example.js
1HTTP/... 200 OK 2 3... 4Content-Type: text/javascript; charset=utf-8
By default Apache maps certain filename extensions to specific media types, but depending on the Apache version that is used, some mappings may be outdated or missing.
Fortunately, Apache provides a way to overwrite and add to the existing
media types mappings using the AddType
directive. For
example, to configure Apache to serve .webmanifest
files with the
application/manifest+json
media type, the following can be used:
1<IfModule mod_mime.c> 2 AddType application/manifest+json webmanifest 3</IfModule>
The same goes for mapping certain filename extensions to specific
charsets, which can be done using the AddDefaultCharset
and AddCharset
directives.
If you don't want to start from scratch, below is a generic starter
snippet that contains the necessary mappings to ensure that commonly
used file types are served with the appropriate Content-Type
response
header, and thus, make your web site/app pass this hint.
1# Serve resources with the proper media types (f.k.a. MIME types). 2# https://www.iana.org/assignments/media-types/media-types.xhtml 3 4<IfModule mod_mime.c> 5 6 # Data interchange 7 8 # 2.2.x+ 9 10 AddType text/xml xml 11 12 # 2.2.x - 2.4.x 13 14 AddType application/json json 15 AddType application/rss+xml rss 16 17 # 2.4.x+ 18 19 AddType application/json map 20 21 # JavaScript 22 23 # 2.2.x+ 24 25 # See: https://html.spec.whatwg.org/multipage/scripting.html#scriptingLanguages. 26 AddType text/javascript js mjs 27 28 29 # Manifest files 30 31 # 2.2.x+ 32 33 AddType application/manifest+json webmanifest 34 AddType text/cache-manifest appcache 35 36 37 # Media files 38 39 # 2.2.x - 2.4.x 40 41 AddType audio/mp4 f4a f4b m4a 42 AddType audio/ogg oga ogg spx 43 AddType video/mp4 mp4 mp4v mpg4 44 AddType video/ogg ogv 45 AddType video/webm webm 46 AddType video/x-flv flv 47 48 # 2.2.x+ 49 50 AddType image/svg+xml svgz 51 AddType image/x-icon cur 52 53 # 2.4.x+ 54 55 AddType image/webp webp 56 57 58 # Web fonts 59 60 # 2.2.x - 2.4.x 61 62 AddType application/vnd.ms-fontobject eot 63 64 # 2.2.x+ 65 66 AddType font/woff woff 67 AddType font/woff2 woff2 68 AddType font/ttf ttf 69 AddType font/collection ttc 70 AddType font/otf otf 71 72 73 # Other 74 75 # 2.2.x+ 76 77 AddType text/vtt vtt 78 79</IfModule> 80 81# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 82 83# Serve all resources labeled as `text/html` or `text/plain` 84# with the media type `charset` parameter set to `utf-8`. 85# 86# https://httpd.apache.org/docs/current/mod/core.html#adddefaultcharset 87 88AddDefaultCharset utf-8 89 90# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 91 92# Serve the following file types with the media type `charset` 93# parameter set to `utf-8`. 94# 95# https://httpd.apache.org/docs/current/mod/mod_mime.html#addcharset 96 97<IfModule mod_mime.c> 98 AddCharset utf-8 .appcache \ 99 .atom \ 100 .css \ 101 .js \ 102 .json \ 103 .manifest \ 104 .map \ 105 .mjs \ 106 .rdf \ 107 .rss \ 108 .vtt \ 109 .webmanifest \ 110 .xml 111</IfModule>
Note that:
The above snippet works with Apache v2.2.0+
, but you need to have
mod_mime
enabled
in order for it to take effect.
If you have access to the main Apache configuration file (usually called httpd.conf
), you should add
the logic in, for example, a <Directory>
section in that file. This is usually the recommended way as
using .htaccess
files slows down Apache!
If you don't have access to the main configuration file (quite
common with hosting services), add the snippets in a .htaccess
file in the root of the web site/app.
For the complete set of configurations, not just for this rule, see the Apache server configuration related documentation.
By default IIS maps certain filename extensions to specific media types, but depending on the IIS version that is used, some mappings may be outdated or missing.
Fortunately, IIS provides a way to overwrite and add to the existing
media types mappings using the <mimeMap>
element under .webmanifest
files with the
application/manifest+json
media type, the following can be used:
1<staticContent> 2 <mimeMap fileExtension="webmanifest" mimeType="application/manifest+json"/> 3</staticContent>
The same element
can be used to specify the charset. Continuing with
the example above, if we want to use utf-8
it should be as follows:
1<staticContent> 2 <mimeMap fileExtension="webmanifest" mimeType="application/manifest+json; charset=utf-8"/> 3</staticContent>
If you don't want to start from scratch, below is a generic starter
snippet that contains the necessary mappings to ensure that commonly
used file types are served with the appropriate Content-Type
response
header, and thus, make your web site/app pass this hint.
Note: the remove
element is used to make sure we don't use IIS defaults
for the given extension.
1<configuration> 2 <system.webServer> 3 <staticContent> 4 <!-- IIS doesn't set the charset automatically, so we have to override some 5 of the predefined ones --> 6 7 <!-- Data interchange --> 8 <mimeMap fileExtension=".json" mimeType="application/json; charset=utf-8"/> 9 <mimeMap fileExtension=".map" mimeType="application/json; charset=utf-8"/> 10 <mimeMap fileExtension=".rss" mimeType="application/rss+xml; charset=utf-8"/> 11 <mimeMap fileExtension=".xml" mimeType="text/xml; charset=utf-8"/> 12 13 <!-- JavaScript --> 14 <!-- https://html.spec.whatwg.org/multipage/scripting.html#scriptingLanguages --> 15 <mimeMap fileExtension=".js" mimeType="text/javascript; charset=utf-8"/> 16 <mimeMap fileExtension=".mjs" mimeType="text/javascript; charset=utf-8"/> 17 18 <!-- Manifest files --> 19 <mimeMap fileExtension=".appcache" mimeType="text/cache-manifest; charset=utf-8"/> 20 <mimeMap fileExtension=".webmanifest" mimeType="application/manifest+json; charset=utf-8"/> 21 22 <!-- Media files --> 23 <mimeMap fileExtension=".f4a" mimeType="audio/mp4"/> 24 <mimeMap fileExtension=".f4b" mimeType="audio/mp4"/> 25 <mimeMap fileExtension=".m4a" mimeType="audio/mp4"/> 26 <mimeMap fileExtension=".oga" mimeType="audio/ogg"/> 27 <mimeMap fileExtension=".ogg" mimeType="audio/ogg"/> 28 <mimeMap fileExtension=".spx" mimeType="audio/ogg"/> 29 30 <mimeMap fileExtension=".mp4" mimeType="video/mp4"/> 31 <mimeMap fileExtension=".mp4v" mimeType="video/mp4"/> 32 <mimeMap fileExtension=".mpg4" mimeType="video/mp4"/> 33 <mimeMap fileExtension=".ogv" mimeType="video/ogg"/> 34 <mimeMap fileExtension=".webm" mimeType="video/webm"/> 35 <mimeMap fileExtension=".flv" mimeType="video/x-flv"/> 36 37 <mimeMap fileExtension=".cur" mimeType="image/x-icon"/> 38 <mimeMap fileExtension=".ico" mimeType="image/x-icon"/> 39 <mimeMap fileExtension=".svg" mimeType="image/svg+xml; charset=utf-8"/> 40 <mimeMap fileExtension=".svgz" mimeType="image/svg+xml"/> 41 <mimeMap fileExtension=".webp" mimeType="image/webp"/> 42 43 44 <!-- Font files --> 45 <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject"/> 46 <mimeMap fileExtension=".otf" mimeType="font/otf"/> 47 <mimeMap fileExtension=".ttc" mimeType="font/collection"/> 48 <mimeMap fileExtension=".ttf" mimeType="font/ttf"/> 49 <mimeMap fileExtension=".woff" mimeType="font/woff"/> 50 <mimeMap fileExtension=".woff2" mimeType="font/woff2"/> 51 52 <!-- Others --> 53 <mimeMap fileExtension=".css" mimeType="text/css; charset=utf-8"/> 54 <mimeMap fileExtension=".html" mimeType="text/html; charset=utf-8" /> 55 <mimeMap fileExtension=".txt" mimeType="text/plain; charset=utf-8" /> 56 <mimeMap fileExtension=".vtt" mimeType="text/vtt; charset=utf-8"/> 57 </staticContent> 58 59 <!-- This is needed only if you are serving .svgz images --> 60 <outboundRules> 61 <rule name="svgz-content-enconding" enabled="true"> 62 <match serverVariable="RESPONSE_Content_Encoding" pattern=".*" /> 63 <conditions> 64 <add input="{REQUEST_Filename}" pattern="\.svgz$" /> 65 </conditions> 66 <action type="Rewrite" value="gzip" /> 67 </rule> 68 </outboundRules> 69 </system.webServer> 70</configuration>
Note that:
web.config
of your
application.For the complete set of configurations, not just for this rule, see the IIS server configuration related documentation.
You can overwrite the defaults by specifying custom values for the
Content-Type
header and the regular expressions that match the URLs
for which those values should be required.
<regex>: <content_type_value>
E.g. The following hint configuration will make webhint
require
that all resources requested from a URL that matches the regular
expression .*\.js
be served with a Content-Type
header with the
value of application/javascript; charset=utf-8
.
In the .hintrc
file:
1{ 2 "connector": {...}, 3 "formatters": [...], 4 "hints": { 5 "content-type": ["error", { 6 ".*\\.js": "application/javascript; charset=utf-8" 7 }], 8 ... 9 }, 10 ... 11}
Note: You can also use the ignoredUrls
property from the .hintrc
file to exclude domains you don’t control
(e.g.: CDNs) from these checks.
This package is installed automatically by webhint:
1npm install hint --save-dev
To use it, activate it via the .hintrc
configuration file:
1{ 2 "connector": {...}, 3 "formatters": [...], 4 "hints": { 5 "content-type": "error", 6 ... 7 }, 8 "parsers": [...], 9 ... 10}
Note: The recommended way of running webhint is as a devDependency
of
your project.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
Found 4/23 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
Project has not signed or included provenance with any releases.
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
64 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More