I can understand why HTML templates (.tpl files) must be processed beforehand (with loadTemplates
) and put into the HeistConfig
. This allow Heist to process the HTML into a more efficient format beforehand.
However, I don't understand why splices must also be created beforehand and put inside the HeistConfig
. What is the benefit of this? I don't see the benefit because splices are computed at runtime anyway. What is the thought process behind this?
I think this may be because a splice can also execute code at load-time (in addition to runtime). Is this the primary explanation?
Splice functions (compiled and interpreted) operate on nodes. Think of splices as having a type signature of Node -> m [Node]
. This is a relatively expensive operation because it's operating at the DOM level. The splice's result nodes get inserted back into the DOM tree, then the entire tree has to be rendered to a ByteString. The idea behind compiled heist was to do as much of this rendering work as possible up front at application initialization time. The output of the initialization would be [Chunk]
where Chunk can either be a static ByteString or a dynamic m ByteString
(actual types are slightly different). Compiled splices have to be processed before the initialization converts the whole template from [Node]
to [Chunk]
. And to maximize runtime efficiency that conversion happens at app initialization time.
For more information check out these links:
http://snapframework.com/docs/tutorials/compiled-splices
https://github.com/snapframework/heist/wiki/Compiled-Splice-Formulations