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 395043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:24:53+00:00 2026-05-12T16:24:53+00:00

I’m working on a forum like page, where changing between pages of a thread

  • 0

I’m working on a forum like page, where changing between pages of a thread pulls in html from an ajax request and inserts it into the div container.

My question, is would it be faster to just get the basic data through json retrieval, and then do something like cloning a message template and inserting the needed data into that template?

  • 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-12T16:24:54+00:00Added an answer on May 12, 2026 at 4:24 pm

    Normally I send just JSON data from the backend, which I then insert into the HTML page however I like.

    IMHO this decouples a bit the backend from the frontend and makes the server side API more reusable/universal.

    I place predefined html parts in the website, these are then filled with the JSON data. I recently built an app where you can browse through images. Always 10 images at a time. The html looked like this:

    <table>
        <tr>
            <td id="img_0"></td>
            <td id="img_1"></td>
            <td id="img_2"></td>
            ....
            <td id="img_9"></td>
        </tr>
    </table>
    

    The JSON was something like that (rough example):

    {images:
        [
            {imgTag: "<img src='foo.jpg' />"},
            {imgTag: "<img src='foo.jpg' />"},
        ]
    }
    

    And in the Javascript I did:

    for(var i = 0; i < 10; i++) {
        var currentImage = response.images[i];
        if(currentImage) document.getElementById('img_' + i).innerHTML = currentImage.imgTag;
        else document.getElementById('img_' + i).innerHTML = '';
    }
    

    This was doable because the amount of data (in this case images) was known: always 10, at most. The grid was predefined and could be filled with the JSON data.

    Of couse this is very fast because JSON responses are most of the time very small (in my case < 2 kb). And inserting data with innerHTML in already existing elements is reasonably fast as far as I know.


    Getting already complete HTML back from an AJAX request to the server is an option for me when the HTML is rather complex and I cannot predefine parts of HTML in the website which then get populated with JSON data.

    For example when I have a blog post and all comments to that blog post are loaded via AJAX (== stupid example), then I would build the HTML on the server side. Because the number of comments can be anything from 0 to N.

    Of couse you could load the comments from the backend like so:

    {comments:
        [
            {text: "some text"},
        ]
    }
    

    And then insert it in the html page by creating dom nodes:

    for(var i = 0; i < response.comments.length; i++) {
        var currentComment = response.comments[i];
    
        var commentDiv = document.createElement('div');
        commentDiv.className = "comment"
        commentDiv.innerHTML = currentComment.text;
    
        document.getElementById('commentContainer').appendChild(commentDiv);
    }
    

    But this normally is not an option for me: constructing complex HTML using document.createElement(‘div’) is in my opinion very annoying.

    There exist Javascript template engines which might make it easier but I never used one.

    In this example case constructing the complete, probably complex HTML on the server side seems much better to me.

    With GZIP you can reduce the amount of data sent over the wire and with a clever caching strategy one can keep down the server load.


    In your case the second approach (getting generated HTML from the server) might seem like the better approach. But it is hard to tell without more complete information.

    This are no definite laws so your milage will vary. Just my experiences so far while working at AJAX web apps.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a view passing on information from a database: def serve_article(request, id): served_article
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has

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.