0

I'm new with Jquery and payed someone to developed a script for me. I notice when I add this script to my website my bandwidth jumps from 1mb's to 5mb's. I have a lot of users on so it leaves me to believe the Jquery part is refreshing to quickly. My question is what do I need to change so it will stop using so much bandwidth in the script below.

Thank you!

<script>

current_time = 1342987067;
start_at = 1342986987;
waiting_time = 120;
break_time = 9999;
view_1 = 'Text removed for example<br>';
view_2 = 'Text removed for example<b><span id="countdown-value"></span></b> seconds.<br>';
view_3 = 'Text removed for example... currently in progress...<br>';
winner = "Text removed for example";

function changeView() {
    if (start_at + waiting_time > current_time) {
        if (break_time < waiting_time) {
            return view_1 + "\n" + winner;
        } else {
            return view_2 + "\n" + winner;
        }
    } else {
        return view_3 + "\n" + winner;
    }
}

function setView() {
    $("#countdown-holder")[0].innerHTML = changeView();
}

function reload() {
    current_time ++;
    break_time = start_at + waiting_time - current_time;
    setView();
    if (break_time <= waiting_time) {
        if ($("#countdown-value")[0] != null)
            $("#countdown-value")[0].innerHTML = break_time;
    } else {
        if ($("#countdown-value")[0] != null)
            $("#countdown-value")[0].innerHTML = break_time - waiting_time;
    }
    setTimeout("reload()", 1000);
}
setTimeout("reload()", 1000);
setView();

</script>
<script>

function setBreakTimeCountdown() {

    breakTimeCountdown = parseInt($("#countdown-value")[0].innerHTML);

    breakTimeCountdown --;

    if (breakTimeCountdown < 0) {

        breakTimeCountdown = 0;

        reload();

    }

    $("#countdown-value")[0].innerHTML = breakTimeCountdown;

    setTimeout("setBreakTimeCountdown()", 1000);

}

setTimeout("setBreakTimeCountdown()", 1000);

</script>
4

2 回答 2

1

None of the calls in that piece of javascript appear to be triggering any requests directly.

However, if any of the variables view_1, view_2, view_3, and winner were to contain HTML that has references to other media resources in them, that could trigger more requests to your server, which would increase bandwidth utilization.

于 2012-07-22T20:09:36.900 回答
0

Nothing in the script seems to be calling back to your site, so I'm guessing it's loading jQuery itself that's the issue?

Easiest solution would be to use the Google Libraries API. Scroll down and get the jQuery link, and replace your local jQuery with that. It will use Google's bandwidth instead.

于 2012-07-22T20:07:46.127 回答