Search code examples
jqueryfirefoxcountdown

jQuery countdown no longer correct in Firefox


I've been using Keith Wood's jQuery Countdown plugin for quite some time now, with success. Since a few days though, I'm getting complains from Firefox users that the time on the countdown clock is wrong.

Some investigation has pointed out that when people using Firefox open up our website, the server times gets read correctly, and cached by Countdown. Only, these days in Firefox, it keeps referring to the server time at which the site was first opened. It doesn't take into account that time has passed since. It does this correctly in other browsers however (and it used to work just fine in FF).

So for example, if I open my website now, and leave it open, then check a page with a countdown in 4 hours, it will be 4 hours off.

This is the code for the countdown:

                    $("#final-countdown-values").countdown({
                        until: theEnd,
                        serverSync: serverBasedTime,
                        compact: true,
                        layout: $("#layout-placeholder").html(),
                        onExpiry: doSomething
                    });

This is the function that reads the servertime:

function serverBasedTime() {

    $.ajax({url: '/ajaxCalls/servertime',
        async: false, dataType: 'json',
        success: function (data) {
            time = new Date(data);
        }, error: function (http, message, exc) {
            time = new Date();
        }});
    return time;

}

Like I said, this has been running without a glitch for years now. The issue is recent.


Solution

  • Well, as Jamie Dunstan pointed out, the problem was probably caused by the new HTTP cache from Firefox. Version 32 had the issue, as does v.33. The solution was adding "cache: false" to the ajax call:

    function serverBasedTime() {
    
        $.ajax({url: '/ajaxCalls/servertime',
            async: false, dataType: 'json', cache: false ,
            success: function (data) {
                time = new Date(data);
            }, error: function (http, message, exc) {
                time = new Date();
            }});
        return time;
    
    }
    

    .countdown itself still caches the serverBasedTime for the running instance, so unlike I feared (see the comments at the original question), the ajax request for the time isn't repeated over and over again when the 15 second "master" ajax request runs.