{{mustache}}
is, in my opinion, a great template library. The question I face is whether to use it in the client-side, or in the server-side.
I am developing an online magazine that will have a main page with one big article and the the rest of its articles in smaller size underneath.
E.g.
+-------------------------------------------------+
| |
| Big Article Image |
| |
| |
+-------------------------------------------------+
Title
Author
+------------+ +------------+ +-----------+
| Image | | Image | | Image |
+------------+ +------------+ +-----------+
Title Title Title
Author Author Author
...
Server-side option
Using {{mustache}}
in the server-side, as a PHP library: when the browser asks for the page, the server will complete the template and send it back.
pros:
- Loading times will be better. The browser, once it has received the html code will know which other resources it has to ask the server for.
cons:
- It will be difficult to integrate with client-side
{{mustache}}
because when the template is parsed, all the "mustache-tags" that were not matched are removed (I do not know if this can be easily and cleanly avoided). - I do not like to modify the interface from the server-side, I rather do it from the client-side, thus the 3-tier architecture seems more clear (you might differ with this).
- I do not have previous experience with server-side
{{mustache}}
.
Client-side option
Instead of plain {{mustache}}
I usually use ICanHas.js
, which wraps {{mustache}}
and makes it incredibly easy and comfortable: when the browser asks for the page, the HTML
is sent, containing all th js
code to ask the server for the JSON
which contains the title, author, and filename of the image.
pros:
- Enhances 3-tier architecture.
- Things like infinite scrolling (an other ajax stuff) are super-simple to add.
cons:
- Load time is worsen. The browser will need to receive the code, make a request for the JSON, and then ask the server for the resources discovered in that
JSON
(like the image filename).
Question
Which one do you think, from your experience, is the best solution? Why?