link rel="prefetch" in Firefox network panel?

373 views Asked by At

i wrote this JS:

var prefetchUrls = function () {
    var prefetchElements = document.getElementsByClassName('prefetch');
    for (var i = 0; i < prefetchElements.length; i++) {
        (function () {
            var el = i;
            prefetchElements[i].addEventListener('mouseover',

            function (e) {
                prefetchTimeout = setTimeout(function () {
                    if (document.getElementById('prefetch-' + el) == null) {
                        var url = e.target.getAttribute('href');
                        var link = document.createElement('link');
                        link.setAttribute('rel', 'prefetch');
                        link.setAttribute('href', url);
                        link.id = 'prefetch-' + el;
                        document.getElementsByTagName('head')[0].appendChild(link);
                    }
                }(el), 200);
            });
            prefetchElements[i].addEventListener('mouseleave', function () {
                clearTimeout(prefetchTimeout);
            });
        }());
    }
}
prefetchUrls();

HTML:

<a href="/echo/json/" class="prefetch">Test 1</a>
<a href="/echo/html/">Test 2</a>
<a href="/echo/xml/" class="prefetch">Test 3</a>

My script creates a prefetch link tag in the <head>on mouseover(after 200 miliseconds) for elements with a "prefetch" class. Works fine so far in Chrome, but theres is no activity in the Firefox Network Panel although network.dns.disablePrefetch is disabled(false) and network.prefetch-next is enabled(true). Any hints?

Fiddle

0

There are 0 answers