Search code examples
javascriptgetxmlhttprequestyoutube-apiyoutube-data-api

Youtube Data API v3 requests sent twice


I'm creating youtube subscribers counter but when I send one request, Google Developers Console says I sent two requests and my quota limit reaches limit twice faster.

I've tried to make the request in Google Chrome and it also makes two requests instead of one.

function getSubsCount() {
    let url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&id=' + id + '&key=' + key;
    $.getJSON(url, data => {
        div.html(data.items[0].statistics.subscriberCount);
    })
}

function getSubsCount() {
    let url = 'https://www.googleapis.com/youtube/v3/channels?part=statistics&id=' + id + '&key=' + key;
    let xhr = new XMLHttpRequest();
    xhr.open('GET', url, true);
    xhr.onreadystatechange = function() {
        div.innerHTML = JSON.parse(xhr.responseText).items[0].statistics.subscriberCount;
    }
}

I am making two requests (2 channels) per 12s, so that must be 0.166req/s, but it is 0.333req/s


Solution

  • When Chrome sends a GET request, it sends an additional request to /favicon.ico, Google created a bad browser for Google APIs