SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2009
    London, UK
    1 Post(s)
    0 Thread(s)

    Question Efficiency... What are the rules?

    There is obviously more than one way to skin a cat. Often the best approach is the most efficient, but how do you work out which is the most efficient way of getting form a to b?

    I'm currently working on a ajax diary application for a content management system, and I have decided that it is the ajax call which will be most expensive in terms of server load. When the user adds an event to the database, rather than reloading the entire month's data, I have opted to manipulate the DOM with javascript.

    This has cost me a lot more in terms of code bloat, but has saved on the ajax call.

    But have I waisted my time? There will only likely be one or two end users for this application, and they will probably only each actually use it once or twice a week to add events here and there.

    It seems I can either push the majority of the work load on to the PHP scripts and use the client-side language to just make ajax calls, or I can reduce the amount of ajax calls and give the client-side script more work to do. But I don't know which would be better for my application.

    Does anyone have any advice or input on how the go about making these decisions.

    Many thanks,

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    2 Post(s)
    0 Thread(s)
    My opinion is that it's better to have less php /ajax calls, and give the client-side script more work to do.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    SitePoint Addict sdleihssirhc's Avatar
    Join Date
    Feb 2009
    1 Post(s)
    0 Thread(s)
    Here's an answer on Stack Overflow that seems pretty relevant:

    In theory, either would be acceptable. In practice, I would lean toward doing as much repetitious work on the server as possible. If you think about it in terms of which can do it faster, you KNOW how fast your server can do it. The resources stay (relatively) constant.

    Doing it in javascript relies on the client environment. With a web application, the client environment is infinitely varied. You never know how much memory a client will have available, so it is impossible to estimate how efficiently they can parse the data. 99% of your clients might be fine, but the other 1% get a locked browser when they use your script.

    The safest bet is always to use known quantities as much as possible. In this case, the sever is your known quantity - do the work there.
    But, here's an answer to a different question with another way to look at it:

    For small number of clients, server side code is generally faster. For very large number of clients, offloading work to client side code can greatly improve performance.
    But ultimately, I think the following comment on that second question is the most relevant:

    It doesn't matter. Performance should be your last concern in web development. Make it secure, functional, reliable and maintainable first.
    So it kind of looks like a gut thing (unless, of course, you have actual data suggesting one route over another). If it makes you feel dirty, then change it.
    I'm the web overlord for Graphic Business Systems

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts