function Prefetch() {
    this.hooks();
}

Prefetch.prototype.hooks = function () {
    var links = document.querySelectorAll('a');

    for (var n = 0; n < links.length; n++) {

        links[n].addEventListener('mousedown', function (event) {
            // Left mouse click
            if (event.which == 1) {
                var prefetch = document.createElement('link');

                prefetch.rel = 'prefetch';
                prefetch.href = this.href;

                document.head.appendChild(prefetch);
            }

        }, false);
    }
};
function Prefetch() {
    this.hooks();
}

Prefetch.prototype.hooks = function () {
    var links = document.querySelectorAll('a');

    var length = links.length;

    for (var n = 0; n < length; n++) {

        var prefetchFunction = function (event) {
            // Left mouse click or Touch
            if (event.constructor.name === 'TouchEvent' || event.which === 1) {
                var prefetch = document.createElement('link');

                prefetch.rel = 'prefetch';
                prefetch.href = this.href;

                document.head.appendChild(prefetch);
            }

        };

        ['touchstart', 'mousedown'].forEach(value => {
            links[n].addEventListener(value, prefetchFunction, false);
        });
    }
};
Add touchstart to support touch devices