1

I have created following simple Razor View:

EmailTemplates/Reset.cshtml:

@model ResetTemplateDto
Rest email @Model.Title

I have called this razor view something like this (via RazorLight):

I am loading Razor Views like EmbeddedResources:

var engine = new RazorLightEngineBuilder()
                .UseEmbeddedResourcesProject(typeof(Program))
                .UseMemoryCachingProvider()
                .Build();

            string result = await _razorLightEngine.CompileRenderAsync("EmailTemplates.Reset", new ResetTemplateDto
            {
                Title = "Test"
            });

If I call this request for the first time this action takes perhaps 4-5s, another calls take 100ms.

Is there any solution how to load razor views without this first long request?

Jenan
  • 3,408
  • 13
  • 62
  • 105
  • On the first call the template is being rendered while any subsequent call can reuse the already rendered template. – poke May 05 '20 at 10:07
  • I have tried render after this first request absolutely different template and another call was really quick. So I do not know where is the issue - it is first call of this library - not first loading specific template. Any suggestion? – Jenan May 05 '20 at 10:15
  • Hi, i'm having a similar problem. Did you found the solution? – raulmd13 Mar 11 '22 at 10:46
  • Yes, I loaded all templates into memory in the Program.cs. Then you can load templates from the memory, not every single request load the whole razor view. – Jenan Mar 11 '22 at 12:31

0 Answers0