To give you some context, I'm working on a single page app:

1. When the user loads a particular page, the app makes 10 independent ajax 
requests to get various pieces of data. Some of these requests take a while 
to complete while others complete instantaneously.
2. In general, it doesn't matter when these requests start and end, but 
there is one particular request which needs to be executed as quickly as 
possible in order to make the page feel snappy.
3. Since the browser can only execute a* limited number of ajax requests in 
parallel, the order of when the requests start is critical.* If my most 
important request is put last in the queue, it won't be executed until the 
AJAX thread pool frees up a spot, which could take a while, resulting in a 
page that feels slow.

With that in mind, and thinking that Cmd.batch would execute my commands in 
the order given, I structured my Cmd.batch like this:

cmd =
    Cmd.batch
        [ getReallyImportantPieceOfData
        , getLessImportantThing1
        , getLessImportantThing2
        , getLessImportantThing3
        , getLessImportantThing4
        , getLessImportantThing5
        , getLessImportantThing6
        , getLessImportantThing7
        , getLessImportantThing8
        , getLessImportantThing9
        ]

The page felt slow, so I opened up Chrome's network tab and found this:

/getLessImportantThing9.json
/getLessImportantThing8.json
/getLessImportantThing7.json
/getLessImportantThing6.json
/getLessImportantThing5.json
/getLessImportantThing4.json
/getLessImportantThing3.json
/getLessImportantThing2.json
/getLessImportantThing1.json
/getReallyImportantPieceOfData.json

My most important request was placed at the back of the queue! Because the 
browser can only execute 5 or 6 ajax requests in parallel, it ended up 
taking a considerable amount of time for my most important request to be 
executed. The solution was simple - I just reversed the list before sending 
it to Cmd.batch - but it left me wondering why Cmd.batch was implemented 
this way.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to