Kam had written an interesting blog post on how to Precompiled view support has been added to Sitecore 8.2 (http://kamsar.net/index.php/2016/09/Precompiled-Views-with-Sitecore-8-2/) I wanted to implement this on 8.1 U3.

We don't have the automatic scaffolding but it turns out that setting this up is very straight forward, install the RazorGenerator.MsBuild task and then using RazorGenerator.Mvc to register the assembly.

We quickly had a working solution that showed really great improvements in the Sitecore first boot time and the time it took to load any page for the first time. We also get the added advantage of compile time checks!

So great everything works fine but the Sitecore backend UI, e.g. Launch Pad and other SPEAK views, was still slow. So we thought why not try compiling these into an assembly?

To do this we performed the following steps:

  1. Create a new Web Project
  2. Copy all the CSHTML files beneath {website}/Sitecore into the new project (Use xcopy). You must keep the same folder structure!:

  3. Add the RazorGenerator.MsBuild nuget to your project.
  4. In your main web project you need to register another View Engine that uses this Web Project as the views assembly. See the notes on RazorGenerator.Mvc on how to do this. 
  5. You should now have two compiled view engines registered in your solution, one for the views in your Web Project and one for the Sitecore Web Project
  6. Disable the PreCompileSpeakViews task in the initialise pipeline, see Kam's config.
  7. Build everything and enjoy the speed improvements.

With these views compiled I can rebuild my solution and get back into LaunchPad in less than 30 seconds. The whole experience also feels more responsive making working with Sitecore even better.

Since you only need to compile these views once it is best not to include this project in your main project because it will make the compile a little slower. A better solution would be to put the DLL into a Nuget package and add this to your project.

 

 

comments powered by Disqus