$ cnpm install @hint/hint-no-broken-links
broken-links)This hint checks and reports if any links in your page are broken.
This includes anchor tag href value, image src value,
script src value, video src value etc.
Broken links gives your user a bad user experience.
This hint gets executed on all the below elements.
img - checks src and srcset attribute valuesscript- checks for src attribute valueanchor - checks for href attribute valueaudio - checks for src attribute valuevideo - checks for src and poster attribute valuessource - checks for src attribute valueobject - checks for data value attribute valuelink - checks for src attribute valuetrack - checks for src attribute valueIf the response status of the resource link is either 404 or 410
or 500 or 503, the URL will be flagged as a broken link.
You can change the HTTP method to make the requests (HEAD, GET,
etc.). To do so, you need to configure the property method in your
configuration .hintrc file:
{
"connector": {...},
"formatters": [...],
"hints": {
"no-broken-links": ["error", {
"method": "GET|HEAD"
}],
...
},
...
}
By default, this hint will use the HTTP GET method to request
the URLs.
<a href="https://example.com/404">Register</a>
<img src="https://example.com/image.png" alt="logo">
<a href="/page-does-not-exist">Profile</a>
<img src="/image_does_not_exist.png" alt="logo">
URLs which return 200 OK will pass this hint.
URLs requested via <link rel="dns-prefetch"> or <link rel="preconnect">
resource hints will
pass this hint if the request succeeds, regardless of status code.
This package is installed automatically by webhint:
npm install hint --save-dev
To use it, activate it via the .hintrc configuration file:
{
"connector": {...},
"formatters": [...],
"hints": {
"no-broken-links": "error",
...
},
"parsers": [...],
...
}
Note: The recommended way of running webhint is as a devDependency of
your project.
Copyright 2013 - present © cnpmjs.org | Home |