Talk

Template engines for the Java ecosystem are stuck in the past. Modern web applications require features and functionalities that can't be offered by existing engines like JSP, Thymeleaf, or Freemarker. That is why JavaScript frameworks like React, Angular, or Vue have seen great success. However, Server-side rendering still has a lot of advantages that those JavaScript frameworks can't take advantage of. New tools are needed if we are to build modern web applications using the Java ecosystem. Taking inspiration from multiple sources, like Twirl and Rocker, but keeping the good parts of well-established technologies like Thymeleaf, I started to create a new template engine for Spring and Spring Boot that tries to offer a viable and modern alternative. That is how Phoenix was born.

Phoenix is a new open-source template engine specifically designed for Spring Boot. It uses a Razor-like syntax to integrate Java code directly into the HTML template. This makes writing and understanding templates easier since there is no special syntax you need to learn and no utilities available inside the templates. You can import and use any Java class from your project with ease and have access to all the functions inside the template. However, Phoenix offers even more features that make it attractive for developers and are not available in other template engines. Templates can be built using fragments that can be imported and reused, helping developers build complex and modular web pages with ease.

Phoenix provides Reverse-routing, allowing you to reference endpoints inside the template easily. Using the `@route` element, you can build URLs directly to your controller. If you change the mapping in the controller, the URL changes without the need to make any changes inside your template file. And yes, dynamic URLs with @PathVariable and @RequestAttribute are supported.

Phoenix allows fragment retrieval from the client side, with the HTML content being generated on the server. The result can then be inserted using JavaScript to create dynamic web pages that can change and adapt over time based on user interactions. Phoenix is not meant to replace JavaScript frameworks, but to work alongside them to create fast and robust web applications.

Despite the complex features, Phoenix is fast. Templates are compiled and the HTML is generated on the server. In internal benchmarks, phoenix is orders of magnitude faster than Thymeleaf and even faster than Rocker.

Learn more about Phoenix, its capabilities, features and limitations at https://pazvanti.github.io/Phoenix/index.html
Petre Popescu
Speechify
I am a software engineer with more than 10 years of experience in the industry. Passionate about Java, Kotlin, AI and more.