-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Hi
I have a need to warm up all my views i.e. compile them before I start using them. The idea is to lower the times of the first user that hits the site. I added code that compiles all my views and it is triggered by the load balancer. The problem is that it takes ages to warm up all views and I cannot get the server out of warm up mode. The same warm up is needed after recycling and this is a big problem for our production environment.
I've looked through the code in RazorMachine and I have the following idea: to compile all views to actual files(dlls) and deploy them as well.
In order to achieve this I need to modify the library in the following way:
In TemplateFactory.cs there is a method: CreateAssembly()
I can change the compilation to be GenerateInMemory = false, and to set OutputAssembly = "to a path" that comes from RazorConfig. (i.e. my bin folder)
i.e. I need to modify the current code which looks like this:
new CompilerParameters(_razorContext.Config.References.ToArray()) { GenerateInMemory = true, CompilerOptions = "/optimize" };
Then I can make a console application in my project that invokes RazorMachine with settings to generate assemblies(RazorConfig will needs some settings about this to work) and the console app will precompile all my views to disk. This console app will be triggered as part of the deployment procedure.
After that I just need to initialize RazorMachine to load the right assemblies in TemplateFactory.cs in CreateBucket() method instead of going in and trying to compile them on runtime.
What do you think about this approach? Is it doable, do you see any gotchas? Will you accept a merge request to put this change into the library if I implement it?
Regards,
L. Toshev