Eric B <ebenze@...> writes:

> I'm still examining the need/use-case for using mustache vs plain JSP for a
light-load server.  I can
> definitely see the value for something that has 
> high load, wanting to offset processing on the client side, but for light
load, I haven't been convinced yet
> that logic-less templates have advantage 
> over JSP models.

Load is not at all the reason why Finn.no uses mustache.

In its simplest form we have client side only templates in mustache used by
JavaScript to render HTML fragments in a clean and simple fashion. Helps us
avoid string concatination and other sorts of HTML generation methods.

We also have other more advanced use-cases as Mick mentions, where we
typically renders the page serverside first, then do AJAX requests (more
accurately AJAJ) and update the page later with the same templates as used
on serverside. Looking back on the JSP to mustache convertions we've done so
far, the nicest feature imho is the logic-less part. It forces our backend
to do the heavy work, leaving the templates with a single responsibility:
presentation. Examples of what I mean by heavy work: generation of URLs,
formatting of text and numbers and most importantly business logic.

As JSPs have all the magic in the world with its taglibs, we have been
tempted way to often to add small pieces of business logic in there. That
logic is often a nightmare to test, we have traditionally ended up writing
cumbersome integration tests. Putting that business logic into the backend
means we could rather write small unit tests, which is perfect as it fails
much quicker and gives developers feedback instantly.

Its worth mentioning we combine JSPs and mustache templates on Finn.no.
Mustache is required when we're doing any AJAX updates after the initial
serverside rendering, otherwise we might just use plain old JSPs. The tiles
taglib helps us do this cleanly as <tiles:insertAttribute name=".." /> can
be used for both types of templates from the JSP.

Getting cleaner templates with business logic where it belongs doesnt force
anyone to use mustache, but it surely forces you to behave.

- Phillip

Reply via email to