I have a web page on which a certain div needs to be refreshed every 3 seconds. This div contains variables that rely on the rest of the content of that page (for example on whether you are logged onto the website, what your username is etc)
I've achieved this refreshing effect via jQuery
setInterval(function()
{
$('#div').load('page.php #div');
}, 3000);
;
The question I have is: ajax loads the whole page before inserting the desired div block into place. The whole page has about 15 queries (maybe a bit more). These queries are pretty simple, just looking up a row or a field (SELECT).
With the above script these 15+ queries will be executed every 3 seconds, thats 5 queries a second. If i have 100 visitors, that is 500 queries a second. Before i go any further i need to know is this too much?
It would be a waste if you are refreshing the div every 3 seconds but are not guaranteed that there are actual changes. How often does the values of the variables in the div change? Is it safe to assume that ALL 15 queries or so and their results are checked every time? (e.g. User A stays on the page for 12 secs, then closes the page - that's 60 wasted queries).
Why don't you just do the necessary checks on certain events like upon clicking of a button or on page load? (e.g. User B stays on the page for 12 sec, then clicks a button - this is the only time you'd check against the database. It might not even be necessary to do 15 or more queries at this point).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With