I am using Mustache.js templating engine.
On page load, I create a list of items which I send back to the Ajax request:
private static List<Items> items;
protected void Page_Load(object sender, EventArgs e)
{
items = service.GetMyItems(0, "text", "someText");
}
In the view, I ask for those items using an Ajax call:
<script>
GetMyItemsByAjax();
</script>
which, on success, creates Mustache HTML from those items, and appends it to some control.
I do it this way, so I avoid waiting time with a blank page while the Items list is being created.
I am curious: is there a smarter way of doing this?
Your way is perfectly valid. The thing I would question is the necessity of using Mustache. Unless you're generating very complex html that the Mustache template would alleviate, you can append the items in the Ajax callback function and skip the client side templating.
It's a balance between: