API / Apache Grails Interview questions
Explain the sequence of events when a GSP page is rendered?
The first time a given GSP is requested, Grails has to compile it into executable code; subsequent requests reuse that compiled form, which is why GSP rendering is fast in steady-state despite starting from a template file rather than pre-compiled code.
The view resolver locates the correct .gsp file by the same controller/action naming convention used for URL mapping, then hands it to the GSP engine, which compiles the template into an actual Groovy class the first time it's needed (or whenever the source file changes, in development), caching that compiled form for subsequent requests. Once compiled, rendering is simply executing that class against the model data the controller returned, resolving any tag library calls (g:each, g:link, custom tags) along the way, and streaming the resulting HTML to the response.
This compile-once, reuse-many-times behavior is why GSP rendering doesn't re-parse the template file on every single request in production — the expensive parsing step only happens once per template (or once per change, during active development with hot-reload enabled).
More Related questions...