How do I stop a dynamic number and type of statements from executing until a series of ajax calls completes?

58 views Asked by At

I have a MVC model website using C# that is created using a series of files. I am trying to use globalize.js for translating dates and date formats. Doing so requires me to load cldr data. I was doing this by using ajax calls with the async flag set to false, like so:

$.ajax({
      dataType: "json",
      url: "/data/cldr/supplemental/likelySubtags.json",
      success: function (data) {
         globalize.load(data);
      },
      async: false
});

This worked, but it slowed down load times to an unacceptable level due to the number of files needed to load (7 x 60-70kb). I'm currently struggling to find a way to load the data before I need to use it without the async flag, because of the modular nature of the site. I need to load the data in the header, which is one file, and use it in possibly 20-30 other modules on each page each in their own file with their own script tags. The issue is that all these modules are loading and erroring out before the globalize.load(data) statement executes.

My question is this: How do I stop a dynamic number and type of statements from executing until a series of ajax calls completes when the two are in separate files? I'm fairly certain the answer will be promises, but I don't see how to make promises behave like I want them to.

0

There are 0 answers