In ASP.NET Core 2.1, I have a DLL project (Microsoft.NET.Sdk) with Razor views for sharing common partial views like navigation, footer, ... with multiple applications. It was created like described here. So I have an ASP.NET Core 2.1 MVC app that includes those libraries and embeds partial views.
While this works, I noticed a large increase in the first page load time in this application. It took about 3 seconds for the main HTML document. Subsequent requests are pretty fast (~30-40ms). I tried removing all the partial view in the application that was embedded by the shared DLL. Now the first request is much faster (about 300ms).
So it seems caused by loading Razor views from the shared DLL project. I tried pre-loading the assembly using different methods like this in AppStartup method (inspirated from this question):
GC.KeepAlive(typeof(Assets.AssetStartup));
System.Reflection.Assembly.Load("Assets");
No large difference in performance, it still took ~2.9 seconds on the first request.
How can I improve this?
I know about warming up from EntityFramework, for this reason, I had the idea to solve this problem in a similar way. But I'm not sure where it exactly slow down my app: Is it the loading of the assembly (and my pre-fetching attempts were wrong in some way), or is it still about Razor compilation?
Because I also know about performance improvements by pre-compiling Razor views. In ASP.NET Core 1, I manually enabled this and the first request was noticeably faster. Since Microsoft re-wrote this part and enabled pre-compilation by default, but my Razor DLL app doesn't generate a file called {AppName}.Views.dll (where MVC apps have them), I'm unsure if this may be the problem.