Experience Editor and other SPEAK applications may take long time to load


Description

When using Sitecore XP 8.0 or later, the Experience Editor and other SPEAK applications may take some noticeable time to load after Application Pool recycle. Application recycle would typically happen when re-compiling the website or adding new assemblies.

The main reason for this behavior is re-compilation of MVC views used by SPEAK components.

Below you can find several ways to speed up loading times of Experience Editor and other SPEAK applications.

Provided solutions may also improve the load times of the whole Sitecore Experience Platform.

Using Razor Generator To Precompile MVC Views

Since Sitecore XP 8.2 Initial Release, there is a possibility to use precompiled MVC views.

By precompiling views you benefit from the following:

Perform the following to precompile MVC views:

  1. Open your MVC solution in Visual Studio.
  2. Install the Razor Generator tool.
  3. Open Properties of your view (.cshtml file).
  4. Set the Custom Tool field value to RazorGenerator and press Enter. In this case, a .cs file with the source code should be created for a view.
  5. Build your project and copy the assembly with precompiled views into the \bin folder of your Sitecore XP solution.
  6. Add the assembly to the sitecore\mvc\precompilation\assemblies configuration section of the Sitecore.Mvc.config file, for example:
    <precompilation>
        <assemblies>
            <assemblyIdentity name="Sitecore.Mvc" />
            <assemblyIdentity name="MyAssembly" />
        </assemblies>
    </precompilation>

Precompilation

Using Sitecore Installer

Since Sitecore XP 8.0 Update 5, the Sitecore Installer contains an option to precompile Sitecore files. It makes installation process slightly longer but Sitecore itself and its components are loaded faster as a result.

The option can be found in IIS Advanced Settings, accessed from the IIS Web Site installation window:

However, please note that the installer precompiles the site only once, so components may load longer again once website files are modified. If this is not acceptable, check the alternatives below.

Using ASP.NET Compilation Tool

In case of installing Sitecore Experience Platform from a zip archive or when performing frequent changes to website files, you can use the ASP.NET Compilation Tool for precompiling the website after the changes or installation as described in the following article:
https://msdn.microsoft.com/en-us/library/ms227972.aspx

In development environments you can configure your Visual Studio project to execute the ASP.NET Compilation Tool as a post-build event. This can be done in the Build properties of your project.

Default precompilation in Sitecore

Please also note, that Sitecore has some precompilation logic in place with the following processor in the initialize pipeline defined in the Sitecore.Speak.config and Sitecore.ContentTesting.config files:

<processor type="Sitecore.Pipelines.Initialize.PrecompileSpeakViews, Sitecore.Speak.Client">

As this precompilcation is executed on the first request to the website it may slow down first request processing and Sitecore in general. 

However, if the site is already precompiled by using the ASP.NET Compilation Tool or with Sitecore Installer, start time should not be affected.

Disabling this processor without preliminary precompilation of the website by other means should speed up the start time of Sitecore application but may slow down SPEAK components, including Experience Editor.

Precompilation info

More information on precompilation can be found in the following MSDN article:
https://msdn.microsoft.com/en-us/library/bb398860.aspx

Optimized Compilation

In order to reduce load time of SPEAK components after website modification, you can alter the compilation element in the web.config by adding the optimizeCompilations attribute to it as follows:

<compilation ...  optimizeCompilations="true">

Adding this attribute will make ASP.NET re-compile only the files that were explicitly changed and leave all the other files intact.

Please note that if optimizeCompilations is true, you might encounter some issues during development after re-compilation. According to the MSDN article:

When you change a top-level file only the affected files are recompiled. This saves time but can cause run-time errors depending on the type of changes you make to a top-level file. 

Please check the Optimizing Dynamic Compilation part of the aforementioned article for more details.

Using SheerUI Ribbon For Experience Editor

Note: This point is specific to Experience Editor.

Loading times of Experience Editor can also be reduced by switching Experience Editor ribbon to SheerUI mode.

SheerUI is a technology which was used in Page Editor prior to the release of Sitecore XP 8.0, so the functionality of the SheerUI ribbon in Experience Editor will be identical to the one in Sitecore 7.2.

You can find instructions on how to perform the switch in the following KB article: KB0359871

Please note that SheerUI ribbon has been replaced by the SPEAK one since Sitecore XP 8.0, so we recommend using SheerUI version only as a last resort. Sheer UI code has been marked as obsolete since Sitecore 8.1 and all the new features that will be implemented for the Experience Editor will only be available in SPEAK mode.

Credits

Sitecore would like to give credit to Kam Figy, Sitecore MVP at Connective DX for publishing some of the optimization ideas in his blog post:
http://kamsar.net/index.php/2015/02/sitecore-8-experience-editor-performance-optimization/