<commit_before>require(['chart', 'page-title', 'page-icon', 'config'], function(chart, pageTitle, pageIcon, config) {

    var pingElement = $('#ping')

    setInterval(function() {
        var ping = chart.addPing()
        $.ajax({
            // Resource has to be: small, close to the user (eg, in a CDN), a 
            // Javascript (TODO really?)
            url: 'http://ajax.googleapis.com/ajax/libs/chrome-frame/1.0.2/CFInstall.min.js',
            timeout: config.maxPing,
            dataType: 'script',
            success: function() {
                ping.pong()
            },
            error: function(xhr, status, error) {
                console.error(error)
            },
            complete: function() {
                pageTitle.update(ping)
                pageIcon.update(ping)
                pingElement.text(ping.lag() + " ms")
            }
        })
    }, config.pingInterval)
})
<commit_msg>Pings where done only every second when the tab was inactive<commit_after>require(['chart', 'page-title', 'page-icon', 'config'], function(chart, pageTitle, pageIcon, config) {

    var pingElement = $('#ping')

    var setRealInterval = function(callback, interval) {
        // "In (Firefox 5.0 / Thunderbird 5.0) and Chrome 11, timeouts are 
        // clamped to firing no more often than once per second (1000ms) in 
        // inactive tabs" http://stackoverflow.com/questions/6585112/javascript-performance-when-running-in-an-unfocused-tab
        var minBrowserInterval = 1000
        var setIntervalsCount = Math.max(1, minBrowserInterval / interval)
        for (var i = 0; i < setIntervalsCount; i++) {
            ;(function(i) {
                setTimeout(function() {
                    setInterval(callback, interval * setIntervalsCount)
                }, i * interval)
            })(i)
        }
    }

    setRealInterval(function() {
        var ping = chart.addPing()
        $.ajax({
            // Resource has to be: small, close to the user (eg, in a CDN), a 
            // Javascript (TODO really?)
            url: 'http://ajax.googleapis.com/ajax/libs/chrome-frame/1.0.2/CFInstall.min.js',
            timeout: config.maxPing,
            dataType: 'script',
            success: function() {
                ping.pong()
            },
            error: function(xhr, status, error) {
                console.error(error)
            },
            complete: function() {
                pageTitle.update(ping)
                pageIcon.update(ping)
                pingElement.text(ping.lag() + " ms")
            }
        })
    }, config.pingInterval)
})

{'fraction_non_alphanumeric': 0.12915552158960641, 'fraction_numerical': 0.01108139090561712, 'mean_word_length': 1.7471143756558236, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1422358', 'n_tokens_mistral': 771, 'n_tokens_neox': 709, 'n_words': 170}