Alex
Alex

Reputation: 67678

Should I limit ajax requests?

Are ajax requests more resource-intensive than a normal page load?

For example, I have a simple menu with normal links (when you click on the link you get on a page).

With ajax, I can prevent this behaviour on click and request the link's href with ajax (GET), then get the html I want from the results and insert it in the current page. Does this use more resources than the normal link behaviour?

Upvotes: 2

Views: 431

Answers (4)

mario
mario

Reputation: 145482

If implemented right AJAX can cause less server load than normal page requests. If you just serve a data request (a little JSON array incoming and outgoing) you do not typically need to instantiate the whole CMS. Simpler handler scripts often suffice.

In your case it sounds like you are just using $("#link").load("frompage.php #link") or something. In which case it makes no difference.

(Request limiting is sometimes advisable for security reasons, or preventing complete database scraping. Not applicable in your case.)

Upvotes: 1

citizen conn
citizen conn

Reputation: 15390

I would use ajax requests only if you want to add enhanced value to the page, by changing the look/functionality after the user has interacted with the page.

It probably doesn't necessarily use more resources than just clicking on the link, but it is definitely faster for the user because it doesn't need to reload all the other content on the page as well.

Most of it has to do with the type of experience you are trying to deliver.

I would try both as an experiment and see which feels better to you!

Upvotes: 3

spender
spender

Reputation: 120498

No extra server resources are required to deliver the content. Take a look in firebug / fiddler / charles. From the server's POV, the requests are identical.

Upvotes: 2

Sophie Alpert
Sophie Alpert

Reputation: 143194

No, it doesn't use any more resources on the server. On the client, it's possible to write inefficient code but that would be a fault of how you load pages, not the actual downloading of the page itself.

Upvotes: 3

Related Questions