Thursday, November 29, 2018

Slow start up time of Sitecore 9 in Azure

Not that long ago we were launching a new Sitecore 9 site in Azure and ran into a big issue with start up time. It was taking over 20 minutes for the application to start from an application pool recycle or a hard stop/start. After countless hours of debugging and running traces, we figured it out. So if you are running into a similar situation, maybe this post will help.


It turns out MVC 5 is mostly to blame for this slowness. There is a very good article written by David De Sloovere that you can read at It covers all configurations and parameters that are needed to make your build pre-compile the views.

In case of Sitecore application, we ended up compiling all views including the Sitecore ones. We have several modules installed in our solution, so the views from those had to be pre-compiled as well. We used aspnet_compiler.exe tool to do that.

Technically, it is really good when you pre-compile the views even for catching the missing references or other problems in the Views before the code gets to target environment. However precompiling the views in local environment will take much longer that a developer would want to work efficiently.

Application Initialization

Another thing that was discovered that might not affact the start up time, but it does affect the moment when application is considered fully loaded. 
    <applicationInitialization doAppInitAfterRestart="true">         
        <add initializationPage="/sitecore/service/heartbeat.aspx" />
        <add initializationPage="/"  />  <!-- home page must load --> 
        <!-- put here all urls that must be loaded before the application is considered 
 to be fully loaded: landing pages, etc. -->

This is more important for the Auto-scaling in Azure.

Thursday, November 1, 2018

Sitecore PxM "Table of Contents" renderers

I just finished a PxM project where one of the requirements was to implement a "Table of Contents" based on the article heading tags. The content of the article comes from data sources of various renderings that assigned to an item presentation settings. The Sitecore data source structure that we had to work with have a separation between section titles and the body, so the task at hand was to parse HTML and find H2 and H3 tags that the "Table of Contents" can be built on.

Here is a screenshot of the Table of Contents in PDF:

To implement this functionality two renderers had to be implemented:

  • Renderer for "Table of Contents" headings;
  • A renderer that would inject the InserVar XML node into the heading ParagraphStyle nodes that would allow for InDesign to determine the page number where a particular heading is placed.

Table of Contents headings

The Table of Contents page displays the list of al H2 and H3 headings from the Article Content with the page number where those headings render in the content section. 

The PxM project structure for TOC looks like this:

The TOC page is of Flow type. It has a TextFrame that holds a Repeater that loops through all renderings in item Presentation settings that live in specified in "Placeholder" parameter placeholder and are based on the template name that is specified in "AllowedRenderingNames".

The "H Tags" renderer is responsible for parsing HTML from each "TextModule" rendering data source, extracting the value of the H2 or H3 tags and rendering a ParagraphStyle XML element with appropriate Style.

In Parameters section of this renderer item the following parameters are defined:
  • HTags – the list of HTML tags to search for to produce the Table of Contents
  • IndexName – the name of the index for the variable list that is used for the Table of Contents
  • ReplaceVar – the substring that would be replaced with the index element order number.
  • HParagraphStyles – the list of ParagraphStyles that should be used for the Table of Contents entries. This parameter goes together with the HTags one. In the example above the H2 tag value would render in PDF with “style 1 Level 1” ParagraphStyle, and H3 with “style 1 Level 2”.
The XML that this renderer produces look like this:

Dynamic Content Renderer with TOC

The Dynamic Content Renderer with TOC is a part of the following PxM project structure:

A similar Repeater creates a loop through the same renderings as the previous renderer. However, in this case, it is not extracting the value of the H tags, but injects an InserVar XML element with the index value.

XML output for this section looks like this:


In combination, these two renderers allow for the "Table of Contents" with page numbers to be rendered in PDF.

Source Code:

You can find the code for these renderers at: