We all love Umbraco because it's easy and fast, right? But it's pretty much always possible to improve the performance of the project you're working on. This blog post has some simple tips and tricks for you on how to do that.

Performance Boosts for Umbraco

Performance is the essence of your website. A slow website has several disadvantages. To improve the performance of your Umbraco site, there are many things you can do. And they won’t even cost you a lot of time. If you want to get a good search engine ranking and not scare away your users, read on for tips and methods.

In this article, I don’t want to write about how to push your site’s performance to the maximum, I will rather tell you about methods you can use on the fly without investing a lot of extra time on your site. If you apply these methods successfully, you will spend close to no extra time on optimising your performance.

Caching

“Caching is for sites with performance problems or for people who have too much time.” – Chances are, some of you have heard a phrase like this on your way to become developer. I’m not entirely sure anymore where I heard it but that’s not why I’m telling you this anyway. I’m telling you because of its message. And the message is – as you probably know – complete nonsense. Caching is essential to boost your site and to get the most out of it. “But what if the site runs quickly already?” – My answer to this question: You can always make it quicker. Plus, caching barely takes any time.

CachedPartials

What can be written almost as quickly as @Html.Partial? You’re right, it’s @Html.CachedPartial! If you have already spent some development time thinking about where it makes sense to use CachedPartials instead of regular Partials, this procedure does not take a lot of time. You can also set further parameters, such as cachedByPage which allows you to get a separate cache per each type of site using the Partial, or cachedByMember with which you can cache for members.

IHtmlString CachedPartial( string partialViewName, object model, int cachedSeconds, bool cacheByPage = false, bool cacheByMember = false, ViewDataDictionary viewData = null, Func<object, ViewDataDictionary, string> contextualKeyBuilder = null)

While developing, CachedPartials won’t get in your way as they only cache with the debug mode set on false. Another thing to keep in mind is that the Partials cache is emptied by Umbraco publish events.

WebApi.OutputCache

How often do we make queries where we know beforehand that they will always provide the same data? Like when we use an WebApi to get settings from the backend. Why should you wait longer than necessary for an answer – especially when WebApi.OutputCache is working in one line? WebApi.OutputCache.V2 is a Nuget package. After the installation, you can apply an attribute to your methods and thereby cache them. See the following example:

public class MyController : UmbracoApiController { [WebApi.OutputCache.V2.CacheOutput(ClientTimeSpan = 60, ServerTimeSpan = 60)] public string cachedFunction(string parameter) { // do something return something; } }

The following properties are available:

ClientTimeSpan (corresponds to CacheControl MaxAge HTTP header)

MustRevalidate (corresponds to MustRevalidate HTTP header)

ExcludeQueryStringFromCacheKey (querystrings get ignored while caching)

ServerTimeSpan (cache period on the server site)

AnonymousOnly (cache enabled only for requests when Thread.CurrentPrincipal is not set)

There are a handful of variations of the output cache: CacheOutputUntil, CacheOutputUntilToday, CacheOutputUntilThisMonth and CacheOutputUntilThisYear. These serve the purpose of setting a specific time at which the site is supposed to be cached.

LeBlender

LeBlender is a free Umbraco package. It lets you build complex grid editors effortlessly. I, for one, could not imagine working without it anymore.

Just build your new grid editor in the developer section as you always do. In the “select a grid editor” section, choose LeBlender Editor.

Now you can simply add properties. You can also use your own datatypes. LeBlender has a built-in cache. You only need to type in the cache period et voilà. You have already done a lot for your site, if you appropriately use the cache period in all editors.

Those of you who don’t know LeBlender yet, should definitely read this: https://our.umbraco.org/projects/backoffice-extensions/leblender/

Further advantages of caching

The most important thing, no matter which kind of caching you’re planning on doing, is to do some thinking about how often data changes in your project and how important it is to have the latest data available at all times – either while you’re developing or even better: before you start. Does it make a difference whether the new data is updated right away or in two hours? If the answer to that question is “no”, you should definitely cache.

Some of you probably work with third-party systems which your client pays for per call. If you cache the result of a call, instead of having thousands of calls you might only have one. Your client will be pleased.

Another advantage is the way of working caching entails. By thinking about data flow from an early point onwards, you avoid errors causing more problems the later they are found. Your team leaders will be grateful.

“Quicker load time or not, if the users of the site don’t need to wait for too long, it’s all the same, isn’t it? After all, they won’t notice one hundred milliseconds more or less.” – The user might not, but the search engines certainly will! Caching has a positive influence on the speed of indexing a site which can help you get a better ranking.

Typed content

Additionally, you should always pay attention to using typed content. As a general rule, typed content is more performant than Dynamics and less prone to errors. If you still work with Dynamics, now would be a good time to change since support for Dynamics for access to IPublishedContent will cease with the introduction of Umbraco version 8.

Common pitfalls and anti-patterns

If you’re new to Umbraco, there are a handful of rules which you should pay attention to in order to avoid errors. I want to send you off with a related our.umbraco article I highly recommend: https://our.umbraco.org/documentation/Reference/Common-Pitfalls/

This article was translated from German. Read the original article on http://www.byte5.de/news/.