Slow webpage possible due to javascript function calls
This is the link to a project i was making http://shout.agilityhoster.com/login.html
Log in with
username: rafa
password: nadal
Now if I log in with another user
username: ana
password: ivanovic
then the website seems to run extraordinarily slowly. Could multiple timed javascript function calls be th开发者_运维知识库e reason? It works perfectly using xampp on my PC..
Thanks
- you have multiple istances where you should have just one;
- you are using inline javascript code where you can just use jquery;
- you are using body onLoad where you should use jquery dom ready;
- you are using multiple ajax POST where you should have only one and use json;
your first account is probably more faster then the second only cause of browser cache, note that local stuff are always more faster then online server depending on it's speed, and bandwidth.
hope this help
i want help you ;)
you have this:
$("#one").css("visibility","visible");
$("#onein").css("visibility","visible");
$("#closeaa").css("visibility","visible");
$("#onein").css("visibility","visible");
$("#Layer22").css("visibility","visible");
should be:
$(".ClassTheeseAll").css("visibility","visible");
or at least:
$("#Layer22,#onein,#Layer22,#closeaa").css("visibility","visible");
you have
<body onLoad="javascript:window.setInterval('open()', 1000000);checkrow();javascript:window.setInterval('check_newmsg()', 1000000)">
should be
$(function() {
setInterval('initAllMyStuff()', 1000000);
});
function initAllMyStuff() {
open();
checkrow();
check_newmsg();
}
function getmsgs()
{
$.post("getmsg.php",{'name':name_one},function(data){$("#one").html(data);} );
$.post("getmsg.php",{'name':name_two},function(data){$("#two").html(data);} );
$.post("getmsg.php",{'name':name_three},function(data){$("#three").html(data);} );
}
should be:
$.post("getmsg.php", { 'name_one' : name_one , 'name_two' : name_two , 'name_three' : name_three } , function(data) { /* loop json and store where needed */ });
you then have:
function open(){
jQuery(window).bind("beforeunload", function(){$.post("logout.php");})
$.post("online.php",function(data){
$("#Layer6").html(data);
});
unload should just be:
$(window).unload(function() {
$.post("logout.php");
});
to be continue...
You have on this page like 3-5 ajax request's per second, it can by sluggish at times just becouse of that. Like Curtis pointed out try to use Network panel in firebug.
Have you tried watching the network traffic with Firebug? That would tell you how long each of your network requests takes, and when they happen.
Like Curtis's answer, you'll want to profile the page with firebug and yslow [ https://addons.mozilla.org/en-US/firefox/addon/5369/ ] . If you find that you're waiting for images and the like, you could potentially swap out the onLoad call with jquery's ready method: http://api.jquery.com/ready/
That could create a perception of performance, even if the other page items aren't loading as quickly.
Terrible Javascript aside, notice that requests to the site, even for the initial login page, are spectacularly slow (for example the login page alone took about 10 seconds to load from here).
Also at some point I received this error from the site:
Web Server: Too many connections!
Check your server side code for performance problems. Make sure your MySQL queries are performant. Make sure the server itself is correctly configured... Of course you have no control of this if you're using shared hosting, and if you're on free hosting you'll just have to live with a terrible slow site.
精彩评论