You may take a look of
Perlet Engine.
The ideas are simple:
- output not HTML string but the DOM structure in the form of LOL (list of lists). It is serialized in HTML at the top level only.
- use subs instead of scripts. There must be only one script on your site: http sever itself.
A design like this seems to be very flexible and clean.
And yes, I know that the serialization procedure is slow -- now I rewrite it with XS.
Thank you for your comments.