SaaS CMS has officially launched! Learn more now.

How to check for a specific block type in ContentArea without loading content


I am searching for a way to check for the existence of a specific type of block in a content area. The presence of the block enables features in navigation, so this check is done on every page load. I want to avoid loading all of the content items in the ContentArea for performance reasons. I was hoping the ContentAreaItem or ContentReference for each item in the ContentArea.FilteredItems collection had some way to determine its destination content type. Any help would be appreciated.

May 30, 2019 19:03

You can obviously cache the result after first load. But if you're only using Episerver's API, e.g. IContentLoader (or IContentRepository) this should already be cached for you.

May 30, 2019 21:04

But that still implies I loop thro every content reference in that ContentArea and load it to determine its type. Doing this on every page load seems like a waste. Is there any way to determine the content type from a ContentReference without loading it?

May 30, 2019 23:49

No there isn't. A content reference holds only the reference (duh :)). In the content area you may also have a display option per item.

But do it once and then cache it, or even better, test it and meaure it and you will probably come to the conclusion that it doens't take that much time. Do you have a lot of items in the content area? The content area is cached and all the items that you load will be cached as well. This seems like micro/premature optimizations. There are worse things you can do that will impact the performance way more. E.g. traversing the content tree a lot every page load.

If you're not happy with that you should probably go for a completely different solution and not rely on a block in a content area at all.

May 31, 2019 7:44
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.