NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.16k stars 1.47k forks source link

Avoid compiling Razor views every time an application starts #2998

Open PaulBol opened 4 years ago

PaulBol commented 4 years ago

Prerequisites

Description

As mentioned in the thread https://github.com/NancyFx/Nancy/issues/2866 compiling Razor views takes time. With the latest package from Nuget I found that launching the compiler for the first view takes 3-4 seconds and each additional view needs around 50 ms to compile.

This is an issue for a Nancy server in an application that users launch and expect to work with as quickly as possible. I understand that with the current Nancy architecture Razor views need to be compiled after each start of an application.

To ensure that a desktop application starts as quickly as possible I came up with a workaround that involves calling GetOrCompileView by reflection and a IViewCache implementation which writes the compiled assemblies to disk and loads them on subsequent starts. Rather hacky to say the least.

What I would like

Steps to Reproduce

System Configuration