1

I'm changing the dns-prefetching href with javascript. I want to know if it is effective. I'have 2 website that share the same javascript.

So i do something like this:

<link id="prefetching" href="//www.site1.com" rel="dns-prefetch" />




var currentDomain = document.domain;

if (currentDomain.contains("site1")) {
    $("prefetching").href = currentDomain.replace("site1", "site2");
    return;
}
if (currentDomain.contains("site2")) {
    $("prefetching").href = currentDomain.replace("site2", "site1");
    return;
}

1 Answer 1

0

It wouldn't hurt to dns-prefetch both domains, simply by adding two <link rel="dns-prefetch"> tags.

Waiting for the javascript to be run, before being able to interpret the (changed) dns-prefetch tags in the <head> of your document would undo the kind of improvement you're after.

Nonetheless, if you do want to find out if your method is working, in Chrome you can see the DNS-prefetching info by opening chrome://dns/ in the address bar.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.