diff --git a/src/links.ts b/src/links.ts index ecd4a6c3..cb832fe2 100644 --- a/src/links.ts +++ b/src/links.ts @@ -40,6 +40,14 @@ export function getLinks(source: string, baseUrl: string): ParsedUrl[] { const elements = linksAttr[attr].map(tag => `${tag}[${attr}]`).join(','); $(elements).each((i, element) => { const values = parseAttr(attr, element.attribs[attr]); + // ignore href properties for link tags where rel is likely to fail + const relValuesToIgnore = ['dns-prefetch', 'preconnect']; + if ( + element.tagName === 'link' && + relValuesToIgnore.includes(element.attribs['rel']) + ) { + return; + } links.push(...values); }); }); @@ -62,7 +70,6 @@ function getBaseUrl(htmlBaseUrl: string, oldBaseUrl: string): string { if (isAbsoluteUrl(htmlBaseUrl)) { return htmlBaseUrl; } - const url = new URL(htmlBaseUrl, oldBaseUrl); url.hash = ''; return url.href; diff --git a/test/fixtures/prefetch/index.html b/test/fixtures/prefetch/index.html new file mode 100644 index 00000000..dfcc9d1a --- /dev/null +++ b/test/fixtures/prefetch/index.html @@ -0,0 +1,8 @@ + +
+ + + + + + diff --git a/test/test.ts b/test/test.ts index ad8a537b..57154918 100644 --- a/test/test.ts +++ b/test/test.ts @@ -257,4 +257,14 @@ describe('linkinator', () => { assert.ok(results.passed); scopes.forEach(x => x.done()); }); + + it('should not attempt to validate preconnect or prefetch urls', async () => { + const scope = nock('http://fake.local') + .head('/site.css') + .reply(200, ''); + const results = await check({ path: 'test/fixtures/prefetch' }); + scope.done(); + assert.ok(results.passed); + assert.strictEqual(results.links.length, 2); + }); }); diff --git a/test/cli.ts b/test/zcli.ts similarity index 100% rename from test/cli.ts rename to test/zcli.ts