I’ve been exploring an idea and would really like to hear different perspectives on it.
What if a PHP template engine (like Blade) moved from being string-based to an AST-driven pipeline (lexer → parser → AST), so it actually understands the structure of the template instead of just compiling it?
The thought is that this could produce a tree representation of the view (some kind of server-side VDOM). With that, it might be possible to clearly separate static and dynamic parts based on AST analysis.
In theory, instead of re-rendering the full HTML on every request, the server could work at a node level:
- identify which parts are dynamic
- track them as nodes in a tree
- and update only those parts when data changes
Something conceptually similar to how virtual DOM works in frameworks like Vue, but driven from the server side.
For example:
- dynamic variables could be detected at compile time
- certain values could be marked as “live”
- the browser could request only those live parts (e.g. via small, specific requests)
- and the response would update only the affected nodes (kind of like DOM morphing instead of full re-render)
I’m not saying this is practical or better — I’m still trying to understand the trade-offs and limitations.
I’d really appreciate your thoughts:
- Does this approach make sense in a server-driven (PHP) context?
- Are there similar ideas or implementations I should look into?
- What challenges do you immediately see (performance, state, complexity, etc.)?
Just looking for an open technical discussion.
Top comments (0)