/    Sign up×
Community /Pin to ProfileBookmark

Does setInterval make a website sluggish?

Hi, I’m currently considering implementing an Ajax script a lá:

[url]http://yensdesign.com/2008/11/creating-ajax-websites-based-on-anchor-navigation/[/url]
And [url]http://beski.wordpress.com/2009/04/21/ajax-pagination-with-anchor-navigation/[/url]

Both of the scripts use a setInterval function, set to every 300ms. I was wondering if this would make my website slow or anything in that manner (particularly slow/old computers) to a noticeable degree?

Thanks for your time

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@thraddashOct 19.2009 — Just remember that setInterval will constantly fire even if the previous Ajax request has not yet completed, unless they have checks in place.
Copy linkTweet thisAlerts:
@sorenchrauthorOct 19.2009 — Just remember that setInterval will constantly fire even if the previous Ajax request has not yet completed, unless they have checks in place.[/QUOTE]

Right, assuming that such an event is accounted for in the code, would the constant hash-checking make the website sluggish?
Copy linkTweet thisAlerts:
@thraddashOct 19.2009 — Hash checking in Javascript is actually very fast in my experience. From the links you provided they don't constantly communicate with the server, so I don't think you will have much of an issue.
Copy linkTweet thisAlerts:
@rnd_meOct 19.2009 — you could speed up the code on the second link considerably by getting rid of the call to eval() every 300ms. eval is slow, and pointless in this code. I don't understand why people stringify timed out function calls, use the dang reference people!

anyways,

[CODE]$().ready(function(){
setInterval("checkAnchor()", 300);
});[/CODE]


into
[CODE]$().ready(function(){
setInterval(checkAnchor, 300);
});[/CODE]
×

Success!

Help @sorenchr spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...