Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4065074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:56:14+00:00 2026-05-20T15:56:14+00:00

I wanted to see different views / opinions on this. I’ve got Jquery invoking

  • 0

I wanted to see different views / opinions on this.

I’ve got Jquery invoking a function through ajax. It loads data two ways:

  1. The ajax script loads JSON data from the same server, then uses JS to parse it and append it into html.

  2. The ajax script loads complete html / script set up directly via that php script that’s called and then JS appends it to html div.

I’d assume #1 is faster since it’s loading a basic JSON array then uses JS to parse it and append to html.

Opinions?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:56:14+00:00Added an answer on May 20, 2026 at 3:56 pm

    There are a lot of variables. #1 may be faster, provided that your JavaScript isn’t assembling the result piecemeal and assuming that the data is markedly smaller than the equivalent markup. If you’re assembling the result piecemeal, or if the data isn’t much smaller than the markup, it may well be slower. It also depends on the speed of the user’s network connection vs. the speed of their CPU and browser (Chrome is fairly fast, IE7 is fairly slow), etc.

    On the piecemeal thing: For instance, if you’re loading a 200-row table, and you’re building up the rows like this:

    // ...stuff that initializes `tableBody` and clears out old stuff...
    for (index = 0; index < stuff.length; ++index) {
        tr = $("tr");
        tr.append("td").html(stuff[i].a);
        tr.append("td").html(stuff[i].b);
        tr.append("td").html(stuff[i].c);
        tableBody.append(tr);
    }
    

    …then that’s probably going to be fairly slow compared with how the browser would blaze through the equivalent markup.

    If, however, you’re doing it more like this:

    markup = [];
    for (index = 0; index < stuff.length; ++index) {
        markup.push("<tr>");
        markup.push("<td>" + stuff[i].a + "</td>");
        markup.push("<td>" + stuff[i].b + "</td>");
        markup.push("<td>" + stuff[i].c + "</td>");
        markup.push("</tr>");
    }
    tableBody.append(markup.join(""));
    

    …you’re in better shape, because there you’re getting maximum reuse out of the browser’s ability to parse HTML quickly (which is, fundamentally, what browsers do, and what they’re optimized for).

    It can seem, on first glance, a bit counter-intuitive that building up a string and then handing it to the browser can be faster (even markedly faster) than building up the structure directly with DOM methods or jQuery. But the more you think about it, the more obvious it is (and yes, I have tested it) why that’s the case. The DOM is an abstraction that the browser has to map to its internal structures, and each call you make to a DOM method crosses a boundary layer between JavaScript and the browser’s DOM engine. In contrast, adding to an array is fast, join is fast (even string concat is fast on modern browsers). Handing the browser a complete string keeps trips between layers at a minimum and lets the browser build up its internal structures directly without worrying about their DOM equivalents (until/unless you ask for them later). The last time I tested this was a couple of years ago, and the results were dramatic. I should try it again with current browsers; no time today, though…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see there is full ajax mode but I wanted to see if there
I know this works in other languages, but wanted to see if there is
Wanted to see if anyone knows how to add props to a image with
I wanted to see what happened if you change the reference of an object
I wanted to see what some suggested approaches would be to validate a field
I wanted to see if there is a cleaner and more effective way of
I just wanted to see if there was a better way I should be
I recently wanted to see if I am able to solve an easy sudoku
Im making an application in cocoa and wanted to see if some strings in
I been playing around with my code and I wanted to see what would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.