I am building a simple charting tool. When a user chooses a data source and a chart type, both the data and the script for the specific chart (.js) are loaded and then the code renders the chart.
Currently I use the following sequence:
To improve performance, I'd like to implement promises and load script and data in parallel. A library like jQuery is too big for my needs (the point of the question is not to argue on this), are there more lightweight solutions? Maybe a 1-2 kb library, or a tutorial? Again, this is a very basic implementation with just two actions in parallel.
[Update] I upvoted all the replies as they all look excellent. I'll report back after I do some more testing.
I strongly suggest using an implementation of the Promises/A specification, which is becoming the standard way of doing promises in JavaScript. Promises work better when everyone uses the same flavor, so it's in everyone's interest to use compatible implementations.
Q is probably the most popular and fully featured implementation (it also will adapt jQuery and other incompatible promises), while when and rsvp are supposed to be more "lightweight".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With