.Net Core 3.1 with Kentico Kontent Part 4: Helpful Tips When Using Linked Items in Kentico Kontent
Be sure to check out the whole .Net Core 3.1 with Kentico Kontent Series:
  1. .Net Core 3.1 with Kentico Kontent Part 1: Clean Architecture Design 
  2. .Net Core 3.1 with Kentico Kontent Part 2: Clean Architecture Implementation
  3. .Net Core 3.1 with Kentico Kontent Part 3: How to Route and Link to Content
  4. .Net Core 3.1 with Kentico Kontent Part 4:  Helpful Tips When Using Linked Items in Kentico Kontent

.NET CORE 3.1 WITH KENTICO KONTENT SERIES PART 4

At BizStream we are always striving to make high performing web apps. Kontent is very helpful in its ease of use and speed. Linked Items have some great uses, but can bloat your API responses. When performance is key we only want to be pulling down the needed information and nothing else. 

small example of how three related articles can add a lot of bloat

The GIF above is a small example of how three related articles can add a lot of bloat. All of these other fields are unnecessary if you only need a couple of fields like the article title, and thumbnail. Let’s jump into some solutions to making your API calls leaner and faster. 

Putting Limits on your Linked Items

Setting limits on your content types is a great way of preventing content admins from overloading pages with 10s of linked items or even more. The cogwheel has some very helpful settings in it. In this Related Articles example below I am allowing At most 3 linked articles. When making a request for the main article I’m going to get back all of the data in these related articles too. If there wasn’t a limit you can see how this page could increase it’s load time pretty quickly. 

The Allowed content types prevent any content admins from adding whatever type they want as a “Related Article”. This ensures when I make a call to the Delivery API will return exactly what is expected. 

Putting Limits on your Linked Items screenshot

If a content admin tries to add more than 3 articles they are notified that this field is Not filled in correctly.

"not filled in correctly" screenshot

Code Solutions

There are a few ways to manage your API response sizes with your code solution. There are a lot of filters and parameters you can tag onto your API calls; let’s breakdown the method below. 
  • Starting on line 34 we are using the deliveryClient to get items that are of type KontentProductDetail. (We have some using aliases at the top declaring which ProductDetails is repository model vs our clean core model) 
  • Line 35 ensures we are retrieving the product detail the user is navigating to. The slug is coming from our ProductsController
  • Line 38 is limiting the response to only one content item. The LimitParameter could be set to 5 and if all the other conditions were met it would grab 5 products. 
  • Line 39 is pretty important to response size. This is how you actually get data from your linked items. Without setting the depth your linked item will return empty. Kentico recommends keeping the depth set as low as possible. 

code solutions snippet

If your product detail has a related products section that displays at most three products’ title, image, and a short description then you might be better off making a service to make two separate calls to the API. If you plan on making two calls the method above wouldn’t need the DepthParameter filter on the call because the related products will be added with the method below. Make sure you are not requesting unused data in your product detail request. The ElementsParameter filter is very helpful in a situation like the related products by limiting the response to only the requested fields.

DepthParameter filter and ElementsParameter filter code snippet

After making this call your service would append the related products to your product detail from the method above. So your service would end up looking something like this. 
  • Line 18 retrieves the base product detail info
  • Line 19 gets the title, image, and description of the related products on that product detail.
example of service

In conclusion, limit your content admins so they can’t add 10s or more linked items in Kontent. In your code solution be sure to only request what is needed and if the content type is complex you might want to consider making a service and making multiple calls. Always remember to optimize your API calls to Kontent to make them that much faster. Kimball Hospitality is a great example of how fast Kontent can be. Chrome Dev Tools Performance tab screenshot below speaks for itself. Sub one second for the home page is great!

Chrome Dev Tools Performance tab screenshot

Be sure to check out the whole .Net Core 3.1 with Kentico Kontent Series:
  1. .Net Core 3.1 with Kentico Kontent Part 1: Clean Architecture Design 
  2. .Net Core 3.1 with Kentico Kontent Part 2: Clean Architecture Implementation
  3. .Net Core 3.1 with Kentico Kontent Part 3: How to Route and Link to Content
  4. .Net Core 3.1 with Kentico Kontent Part 4:  Helpful Tips When Using Linked Items in Kentico Kontent

Share This Post:

Twitter Pinterest Facebook Google+
Click here to read more Kentico posts
Start a Project with Us
Photo of the author, Ian TeGrootenhuis

About the author

Ian was raised in Allendale, Michigan and has lived there his whole life. He loves the location; being a few minutes from the Lake Michigan and downtown Grand Rapids in a small town is perfect. From an early age he fell in love with video games and wanted to develop them. In pursuit of following his dream he found Bizstream Academy, and signed up to gain some coding experience. Ian loved the Academy so much his passion changed to web development. In his spare time Ian still plays video games.

View other posts by Ian

Subscribe to Updates

Stay up to date on what BizStream is doing and keep in the loop on the latest with Kentico.