The usual approach is something like this:
<div id="myposts-widget" data-customer-id="42">Loading...</div> <script src="https://www.myposts.com/widget.js"></script>
First, the browser loads, parses and executes the script. Then, the script looks up the customer ID, fetches the list of posts and renders the widget. It is simple and it works. But the main drawback of this approach is the latency introduced by having two roundtrips to the server: one to fetch the script, another to fetch the data.
The code would look like this:
<div id="myposts-widget">Loading...</div> <script src="https://www.myposts.com/widget.js?customer_id=42"></script>
I had a look at numerous widgets/embeds all over the web, and it’s like everybody uses the first approach (with two roundtrips). Am I missing something? Do you have any recommandation or comment?
(Edited for clarity)