npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hint/hint-no-broken-links

v4.2.26

Published

Verify that all links and resources the page uses are available online.

Downloads

160

Readme

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.

Why is this important?

Broken links gives your user a bad user experience.

What does the hint check?

This hint gets executed on all the below elements.

  1. img - checks src and srcset attribute values
  2. script- checks for src attribute value
  3. anchor - checks for href attribute value
  4. audio - checks for src attribute value
  5. video - checks for src and poster attribute values
  6. source - checks for src attribute value
  7. object - checks for data value attribute value
  8. link - checks for src attribute value
  9. track - checks for src attribute value

If 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.

Can the hint be configured?

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.

Examples that trigger the hint

Absolute URL

<a href="https://example.com/404">Register</a>

<img src="https://example.com/image.png" alt="logo">

Relative URL

<a href="/page-does-not-exist">Profile</a>

<img src="/image_does_not_exist.png" alt="logo">

Examples that pass the hint

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.

How to use this hint?

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.