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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:21:54+00:00 2026-05-31T01:21:54+00:00

I’m trying to get my head around JQuery Deferred object. I’m working on a

  • 0

I’m trying to get my head around JQuery Deferred object. I’m working on a JS framework which loads a template and some JSON object and produces some HTML using those. The initial approach was loading them sequentially (pseudocode):

load_template(template_url, function (template_data) {
    load_json(json_url, function (json_data) {
       render(template_data, json_data);
    });
});

which is suboptimal, because json only starts loading after the template is loaded. I modified this to use Deferred object:

$.when(load_template, load_json).done(function (template_xhr, json_xhr) {
    render(template_xhr[0], json_xhr[0]);
});

So far so good. Now I have co-called “partials” which are some inline pieces of HTML which are built from a separate template and JSON data which are requested asynchronously and then inserted into the page. Currently I start loading them after the main template is rendered:

load_template(template_url, function (template_data) {
    load_json(json_url, function (json_data) {
       render(template_data, json_data);
       $.each(partials, function (idx, partial_url) {
           load_partial(partial_url, function (partial_data) {
               $("#some-element-id").html(partial_data);
           });
       }); 
    });
});

which, again, is sub-optimal, because I could start loading them concurrently right after the main template.

The problem with this, however, is that the partials can finish loading before the main template is loaded and rendered, so there’s nowhere to insert them. Or they can finish later.

Sticking them into a single $.when() call is not good because I would like to display the page as soon as the main template and JSON data are ready, so the following would not work:

$.when(load_template, load_json, load_partial_template, load_partial_json, ...).done(function (template_xhr, json_xhr, ...) {
    render(template_xhr[0], json_xhr[0]);
    insert_partial(...);
});

So, the question is:

Is it possible, using Deferred object, to set up a series of ajax requests so they are divided into several groups:

  • all requests are initiated at the same time
  • when requests from “group 1” are finished a callback function is invoked
  • callbacks from “group 2″…”group n” are guaranteed not to be invoked before “group 1” callback, but they are still invoked eventually – either after the respective request completion or after the “group 1” callback, depending on what took longer.
  • 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-31T01:21:55+00:00Added an answer on May 31, 2026 at 1:21 am

    Can you set up a collection of Deferreds for your partials, and a single main Deferred, and then only do something with the partial results after the main Deferred has finished?

    var dfdPartials = [];
    $.each(partials, function (idx, partial_url) {
        dfdPartials.push($.when(createDeferredForPartial(partial_url));
    });
    
    var dfdTemplate = $.when(load_template, load_json).done(function (template_xhr, json_xhr) {
        render(template_xhr[0], json_xhr[0]);
        $.each(dfdPartials, function (idx, dfd) {
            dfd.done(function (partial_data) {
                $("#some-element-id").html(partial_data);
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.