Feather: Precompile the view templates of a custom widget assembly
Feather widget assemblies contain the view templates embedded into the assembly. The view templates are retrieved and compiled when a widget is rendered. Because of this, there is a delay of several seconds before a widget is rendered for the first time while the web application is running.
To avoid the initial rendering delay, you can precompile the templates so that they are ready for rendering when the widget is requested. This article describes how to precompile the templates in a widget assembly.
PREREQUISITES: You must have a Feather widget assembly and the views must be templates in C# Razor format (.cshtml
)
Keep in mind that when creating a new project, the views from the ResourcePackages folder are also precompiled in a dedicated DLL file - SitefinityWebApp.ResourcePackages.[NameOfPackage].dll. As a result, if you delete a template, for example, List.NewsList.cshtml from the News folder, the template still works on the frontend because it is loaded from the precompiled DLL file. You can disable this behavior by rebuilding your project.
To precompile the view templates:
- Install
RazorGenerator.MsBuild
package in the widget assembly project.
To do this, in the Package Manager Console, execute Install-Package RazorGenerator.MsBuild – Version 2.4.1
- Build the project.
RESULT: The built assembly contains the precompiled views that Feather will use.
NOTE: All view templates must remain embedded in the assembly.