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.

 

 

Glass needs your support!

Glass.Mappper.Sc is supported by the generous donations of the Glass.Mapper.Sc community! Their donations help fund the time, effort and hosting for the project.

These supporters are AMAZING and a huge thank you to all of you. You can find our list of supporters on the Rockstars page.

If you use Glass.Mapper.Sc and find it useful please consider supporting the project. Not only will you help the project but you could also get a discount on the Glass.Mapper.Sc training and join the Rockstars page.

Become a Rockstar