Find dead URLs and fragment identifiers.

Usage no npm install needed!

<script type="module">
  import deadlink from '';


Travis build status NPM version

Find dead URLs and fragment identifiers (URLs with a hash and a corresponding ID element in the resulting document).

Deadlink is using a combination of header inspection, data inspection (2015-08-06: mmmagic has been temporary removed until issues with iojs 3.0.0 are resolved) and content length inspection to determine if the content exists, when to listen for the response, and when to bail out.

Deadlink is using jsdom to load the document and execute it. Therefore, resolving fragment identifiers will work even if the element IDs of the resulting document are generated dynamically after DOMContentLoaded event.



This guide explains the most common use case, without going into details about the properties of the intermediate results. Some of these properties are useful for further analyzes, such as knowing when to load the document to extract the IDs for fragment identification.

Refer to the test cases for the detail explanation of Deadlink behavior.

var Deadlink = require('deadlink'),
    deadlink = Deadlink();

Resolving URLs and Fragment Identifiers

This is a convenience wrapper to resolve a collection of URLs, including the fragment identifier when it is part of the URL. URL/Fragment Identifier is resolved with a promise that in turn resolves to Deadlink.Resolution.

var promises = deadlink.resolve([

Use Promise.all to construct a promise that resolves when all of the promises in the collection are resolved. Deadlink.Resolution of a successful resolution does not have an error property.

Promise.all(promises).then(function () {
    promises.forEach(function (Resolution) {
        if (!Resolution.error) {
            // OK

Resolving URLs

The same as deadlink.resolve() but limited to URL resolution.


Special Case

There is one special case when promise for a valid response can be rejected.

It is rejected if Content-Type is text/html and content length is larger than 5MB. Deadlink is storing the response of text/html in case resolveFragmentIdentifierURL will be referring to the said URL in future. If you foresee this as an issue, raise an issue stating your use case.

Resolving Fragment Identifiers

The same as deadlink.resolve() but limited to Fragment Identifier resolution.


The resolution object reflects the type of the resource:


All of these objects extend from Deadlink.Resolution.

The test cases explain what properties and when do each of these objects have.

Matching URLs

deadlink.matchURLs(inputString) collects all URLs from a string. This function is a wrapper around URL RegExp match().


Download using NPM:

npm install deadlink