-
Is there a way to use precompiled views for Razor? We have a big process with a lot of custom code, so we're going to look into potentially forking the built-in Razor module to support precompiled views, but wanted to make sure that we weren't missing this featured being available already. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Statiq kind of already does it (it just does it behind the scenes in a way that isn't obvious). An attempt is made to cache all the compiled Razor assemblies to disk in the It's not foolproof though, and ensuring cache hits was a PITA - it still sometimes thinks it needs to recompile when there's a cached Razor compilation available. You can generally see the cache in action by running with the
And then at the end of execution you should see something like:
That said, I'm seeing more misses than I expect just now while running to copy-paste here, so the caching behavior could obviously use more work. Improving that, or even just using it as a starting point would probably be a good place to start. |
Beta Was this translation helpful? Give feedback.
-
I was able to track down how the Razor Compiler looks for pre-compiled views and to feed it our assembly so that it never tried to use any view files in the file system. After calling
|
Beta Was this translation helpful? Give feedback.
I was able to track down how the Razor Compiler looks for pre-compiled views and to feed it our assembly so that it never tried to use any view files in the file system. After calling
services.AddRazor()
, I call this method, passing in a type from the type that has the views (since this is .NET 3.1 it generates a sidecar assembly with.Views
added to the name; in .NET 6, these get added directly to the main assembly, so that piece won't be needed going forward).