Hiding unneeded Components to speed up Sitecore Experience Editor

Sitecore Experience Editor is very powerful but if you have lots of components on a page it can be slow to load sometimes. Because of this as a Sitecore developer you often find yourself looking at what you can do to speed it up. The first steps are usually to ensure you are following the recommendations in Sitecores Performance Tuning Guide. Also in more recent versions of Sitecore such as Sitecore 8.2 there are improvements in the performance of Experience Editor by Lazy Loading components in the Ribbon and so on – so if upgrading in the immediate future is an option this is recommended. If it isn’t and you are stuck on Sitecore 8.1 then also look at the following potential improvements: Disabling the My Items count (there is also a Support Hotfix for this now) and turning off the Suggested Tests count.

What else can I do to speed up Experience Editor?

So as the title of this post suggests we can also look at hiding components or partials that are not needed during Experience Editing. This might be things like a Google Tag Manager partial, Social Share Buttons or in our case ReciteMe and a partial that got a list of notifications from a 3rd party feed. These are all things that don’t need to be loaded when using Experience Editor and add to the page load time.

Show me the code

There are a number of ways to do this but since were using Sitecore MVC it seemed nice to do it with an MVC FilterAttribute. Create a class with the following code:

using System.Web.Mvc;
public class ExcludeFromExperienceEditor : FilterAttribute, IActionFilter
{
public virtual void OnActionExecuting(ActionExecutingContext filterContext)
{
if (Sc.Context.PageMode.IsExperienceEditorEditing || Sc.Context.PageMode.IsExperienceEditor)
{
filterContext.Result = new EmptyResult();
}
}

public void OnActionExecuted(ActionExecutedContext filterContext)
{
// Not required
}
}

This uses the inbuilt Sitecore PageMode.IsExperienceEditorEditing and PageMode.IsExperienceEditor to check if Experience Editor is being used. It then returns an empty view result to the controller.

Then decide which of your components and partials are not needed in Experience Editor and decorate their controller actions with the new FilterAttribute like so:

public class GoogleTagManagerPartialController : BasePartialController
{
[ExcludeFromExperienceEditor]
[ChildActionOnly]
public ActionResult Index()
{
//code removed for simplicity
}
}

Thats all there is to it. You can exclude as many components in this way as you like very quickly and you should see some performance gains from doing so. Just make sure you don’t accidentally exclude anything your content editors need to see when editing the page!

Feel free to tweet me or leave a comment if you have other ways of doing this or some improvements.

Published by

Adam Seabridge

I am a Freelance Sitecore Developer and 6x Sitecore Technology MVP (2023 - 2018). I have been working with Sitecore since 2013. You can reach me on twitter @billyjava or comment below if you have any questions or feedback.

Leave a Reply

Your email address will not be published. Required fields are marked *