posted 5 years ago
Here's something that everyone looking for page performance should be aware of. Most modern web clients do not make their requests serially. In other words, fetch CSS #1, JS #1, CSS 2, and so forth. Instead they run multiple requests in parallel. Last time I checked Firefox, for example, it would have up to 10 requests in process by default.
And, since network processes are indeterminate in duration, that means that the exact order in which they complete is also indeterminate.
So when you absolutely positively must assure that some things are there when other things need them, you have two choices:
1. Have the need-er include logic that causes it to wait on the need-ee.
2. Set up a dependency chain as Stephan demonstrated so that the need-er doesn't begin to get get fetched until the need-ee is ready for it.
Either option is good. Which one is best for your situation may vary.
This sort of thing dates way back. Nothing more annoying that trying to manipulate a DOM that hasn't been fully build yet.
Experience keeps a dear School, but Fools will learn in no other.
---
Benjamin Franklin - Postal official and Weather observer