Skip to content

Why Razor?

Marco Cantu edited this page Sep 30, 2016 · 1 revision

By default, Delphi uses PageProducer components to customize the HTML returned by a WebBroker server. This is way too limited, and hasn't even got a clean way to have a shared template for the web site pages. Also, the tag-based notation (<#custom attrib="value">) is not very easy to use.

Looking around, I found the Razor engine for ASP.NET, developed by Microsoft, quite nice. So the previous tag will become @custom.value. The current aim is to have a minimum of data access, loops, conditional statements, and a way to merge a template with given page. And a light translation support. While the ASP.NET version goes a long way allowing complex expressions and processing within the HTML files, my preference is to keep the notation minimal, and delegate all real processing to the backend compiled application.

In real world scenarios, server side HTML generation is combined with JavaScript REST calls to the server and other mechanism. In theory, there is nothing preventing you to use the scripting engine for files other than HTML, but I generally prefer using specific libraries for JSON RESTD processing.

Building plain HTML has many advantages in terms of performance, web site responsiveness, visibility to search engines, and more. This is why generating HTML remains a critical activity for web developers.

Clone this wiki locally