How does Views/Templates actually work in procution

This is a continuation of the talk about how Views work from the discussion in:

It’s been moved to it’s own topic since it technically isn’t related to the original topic.

Hopefully we can all learn at bit more about how templates work in production on Umbraco 16.

I hope tagging you, @JasonElkin, here is okay, so we can continue our talk here :slight_smile:

1 Like

Basically runtime compilation is always on. Umbraco has a dependency on Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation and so long as that DLL is loaded, runtime compilation is turned on.

Apart from being able to modify views in production, there are also some performance considerations. There are filewatchers on views, and requests will check that views are not newer than compiled resources before serving a view (i.e. every request = call to disk instead of just memory). Actually, this is what alerted us to the situation, we were profiling a high traffic site and trying to work out where the extra calls to disk where coming from.

RuntimeCompilation is being deprecated in .NET 10 though, and HQ are going to get to work removing it - probably not in time for v17.

A few other relevant bits of info:

Awesome references!

To recap what I, think, I know so far about the razor pages in production.

  • Following Umbraco best practice one should pre-compile views for prod
  • The actual razor page(.cshtml) should not be included in the output for prod
  • Running Umbraco in production mode should disable viewing and editing of the razor pages

What I really want to know is how Umbraco interacts with the razor pages in production mode and everything pre-compiled.

Say I SSH into a server that is in production mode and has the razor pages compiled and part of the binary.
If I create a Razor file with the same name in the same location, would that really take priority over the one inside the DLL?

Also how is this option in my .csproj needed for backoffice to function?

<PropertyGroup>
    <!-- Razor files are needed for the backoffice to work correctly -->
    <CopyRazorGenerateFilesToPublishDirectory>true</CopyRazorGenerateFilesToPublishDirectory>
</PropertyGroup>

From what I can see my razor files are actually not present in prod, but this comment states otherwise.
Is it just a case of this is required when not in production mode :thinking:


:up_arrow:
Does this mean that all Umbraco sites running in production mode suffers from this, even when the razor pages are part of the same DLL?

This is what I’m not sure about. The behaviour of the Templates in the Backoffice is kind of broken without these files, and it really doesn’t matter if you do include them on prod. The question is if you care about that feature looking wrong.

Kevin’s posted some screenshots of what happens on this related post.

From what I’ve seen, yes. It’s not a massive problem - but if you’re trying to run Umbraco in certain high-performance scenarios it can become noticeable.

HQ did fix this, and in time for v17!

In v17, if you remove the reference to `Umbraco.Cms.DevelopmentMode.Backoffice` in new installs, or don’t add it in upgrades, then the dependency on Razor Runtime Compilation is gone.

More details in the Version Specific Upgrade notes in the docs:

1 Like

Oh damn!
I definitely have to play around with V17 soon.