New releases, publishing, Sitecore, Uncategorized

Dedicated image server in Sitecore – part 2

I have earlier blogged about setting up a dedicated image server for Sitecore here. The implementation required some customization of the LinkProvider, but from Sitecore 6.3 it is possible to achieve the same just using configuration.

A dedicated media server can be used to serve media on a separate URL, so that you can optimize performance due to limitations on the amount of connections the browser can open to the domain, which I also described in the last post. Further it can be used to optimize your server for handling media and supporting a CDN.

As mentioned it is now possible to have a separate server for media by configuration. In this scenario you might have a dedicated publishing target for media, and this should just be a standard Sitecore installation, which then only handles media by directing the DNS for your image URL to this server. For instance I have setup three Sitecore installations – one as a content manager server, one as the dedicated image server and one as content delivery server. The domain for my content management server is http://sitecore63/, the one for my image server is http://sitecore63imageserver/ and the content delivery server has the domain http://sitecore63cd/. What I then want to achieve is:

  1. That my content management server serves images in the normal way, so that the editors can insert, alter and preview images without having to publish.
  2. On my content delivery servers I want my images to be served by the image server.

The first goal is easy. I just leave every configuration to the standard. This means that the content management server serves media itself.
The second goal requires some configuration changes. On the content delivery servers I must make all media references point to the image server. This can be done by setting the Media.MediaLinkPrefix in the web.config to the domain name of the image server plus the media prefix I want. For instance like this:

<setting name=”Media.MediaLinkPrefix” value=”http://sitecore63imageserver/~/media/” />

This means that all media items on the content delivery server(s) will be prefixed with the above url:

<img width=”128″ height=”128″ alt=”” src=”http://sitecore63imageserver/~/media/Images/user.ashx?w=128&amp;h=128&amp;as=1“>

So in this scenario the html is delivered by http://sitecore63cd and the image is served by http://sitecore63imageserver. In the content management environment, the media is served locally. Now this is a lot easier, than the customization you needed in older versions of Sitecore.

dedicated image server in sitecore

If you want another media prefix then the standard /~/media, you also need to make the media server handle these requests as media. This is done by adding the prefix to the <mediaPrefix> element in the web.config and add the prefix to the customHandlers section in the web.config.

Standard
Uncategorized

Hidden functionality: The XPath Builder

Maybe it is just me, who never found it, but after a support request I was made aware of a feature in Sitecore, I have missed for years. I thought I’d just share it, if there were any others like me, who wasn’t aware of the great Sitecore application XPath Builder.

Whenever I create a template which uses a Sitecore Query to populate a multilist field with items, I always spend a little too much time figuring out the correct syntax for the Sitecore Query. But no longer… now that I have found the XPath Builder!

The XPath Builder is triggered in the Developer Center through the Tools menu. The application helps you build the right query and shows the result of the query:

Sitecore XPath Builder

The XPath Builder in Sitecore

Yay! What a great tool!

Standard
New releases, Sitecore, Uncategorized

What TODO – in Sitecore 6.3

Sitecore 6.3 was recently released. A lot of great improvements was included in this version – for instance support for multiple backend web servers and Windows Azure support. Read more about it in Marco Tana’s blog post and read more about the event queue on Adam Conn’s blog.

Besides these new features  a huge amount of bug fixes has been included. Some of them quite important; some of them quite funny…

Almost two years ago I wrote the blog post What TODO? In short I described the somewhat weird way of marking TODO’s by the kernel develepors at Sitecore. Well guess what… In Sitecore 6.3 they thought they would finaly do something about it. It has now…. been marked as obsolete (?!).

“The Sitecore.Todo class has been marked as obsolete. (323278)”

I must admit it made me laugh again. Why not just remove it, when you decide to do something about it?

Standard
.NET, Architecture, Sitecore, Uncategorized

5 worst code smells in Sitecore

Last year I wrote a blog post on doing code reviews on Sitecore. While dealing with conceptual issues it doesn’t really say what to look for in code, when evaluating the quality or to evaluate if any wrong decisions have been made when developing the solution.  Therefore I wanted to wright a post about the top 5 code smells I look for, when I am trying to evaluate or trouble shoot a Sitecore solution. These code smells often indicate that the developers have gone down the wrong road and there is something fundamentally wrong in the architecture.

So here goes:

1) Using the descendant axes in xpath expressions:

This one I especially look for, when I am looking at a site which doesn’t perform. It may be used in some cases, but very often I find that a developer has used this to generate relations between content and thereby iterating over the complete content tree. This works fine in development where there are a few hundred content items. However in production where thousands of items are created this simply breaks the performance of the site – especially after publishing which clears the HTML cache.

The descendants can be accessed in multiple ways. In XSLT it normally looks like this:
<xsl:for-each select=”$sc_currentitem/descendant-or-self::item”>
</xsl:for-each>Or like this:
<xsl:for-each select=”$sc_currentitem//item”>
</xsl:for-each>

In C# using the Sitecore API it is most often accessed like this:

item.Axes.GetDescendants()

2) XSLT Import:

This is related to a point in the post about code reviews on Sitecore, where I argue that overcomplicated functionality and logic in XSLTs, is a problem. If you need to do an import of another XSLT in your rendering, you probably do it to call a method or in another way try and reuse functionality. If you want to do this, don’t use XSLTs! XSLTs should only – if you really want to use them at all – hold simple presentations.
XSLTs can be imported like this:

<xsl:import href=”YourOtherXslt.xslt” />

3) Explicitly accessing the master database

Although this can be needed in some cases and especially in scheduled tasks or other backend functionality, most often it is because the developer haven’t thought the issue through or if they have made a wrong decision of how data entered by the user should be stored.
The master database is most often used like this in c#

Database masterDatabase = Database.GetDatabase(“master”);

If you see a call like this, your solution is most likely not ready for staging, where there is no access to the master database from the content delivery server. You should generally use something like this:

Database database = Sitecore.Context.Database ?? Sitecore.Context.ContentDatabase;

This means you operate on the context database and on the content delivery databases this will be the web database and in preview you will use the master database, which is probably what you want.
If you need to write something to the master database, you first need to decide if this is a good idea at all. If you write to the master database from your frontend, you make yourself vulnerable for malicious attack, as people from the outside can enter data into the master database. Normally we handle user entered data in a custom database or parse all user created content to ensure that the master database won’t be flooded with data.
If you really need to access the master database, you should create a service that handles access to the master database, so that your solution is ready for staged environments.

4) XSLT extension over 100 lines of code:

This point is closely related to point number 2, but I really see a lot of issues with XSLTs which have been used wrong and this creates a lot of issues later on in the project lifecycle. If you have an XSLT extension with over a hundred lines of code, chances are, that the developer made a wrong decision when creating the XSLT; instead he/she should have created a sublayout.
XSLT extensions are functional programming and you should use an object oriented approach, so my advice is not to use XSLTs at all, unless you are doing something really simple. Otherwise your solution will become harder and harder to maintain, as utility methods like the XSLT extensions are very hard to understand and couplings in the renderings themself are difficult to map.
You can find all registered XSLT extensions in the web.config under xslExtension and it looks something like this:

<xslExtensions>
  <extension mode=”on” type=”MyNamespace.XslHelper, MyAssembly” namespace=”http://www.example.net/helper” singleInstance=”true”/>

5) Clearing of cache

This may seem obvious to some, but I have seen surprisingly many methods, which cleared the entire Sitecore cache including the data and item cache. If you see this in your code and it is needed, chances are, that you have an architectural issue in your solution. It should most rarely be needed to clear the cache, unless it is after a publish and Sitecore handles this automatically. I have heard many reasons for clearing the cache including an issue, where the developer argued that it was necessary, as he wrote directly to the Sitecore database with a SQL statement, and then Sitecores cache wasn’t updated.
If you experience something like this, the issue is of cause not the cache, but that you don’t use the Sitecore API to read and write data from the database.
The caching is most often cleared like this:

CacheManager.ClearAllCaches();

This is just some of the things I have seen many times, but I know there are many other bad code smells when developing Sitecore solution. Do you have any other code smells to share?

Standard
IndexViewer, Lucene, New releases, Sitecore

Sitecore Lucene index viewer 1.2 released

Last week I was contacted by the Sitecore Shared Source coordinator Jimmie Overby and he told me that a guy in the Sitecore Ukraine office had made some changes to the Sitecore Lucene IndexViewer, I released some time ago. At first I was a bit sceptic about it, so I asked to review the code changes and see the new functionality. So I installed the new package and looked through the code, and I discovered that the Sitecore Ukranian Vyacheslav Tronko (don’t ask me to pronounce it:)) had done a fantastic job!

Not only had he added some very nice features but he had rewritten some of the code so the application is more stable and extendable. So I really appreciate his work!

The new features are:

  • Possibility to browse indexes defined in the new search section in the web.config
  • Rebuild indexes through the IndexViewer (which is really nice, as you can’t rebuild the new type of indexes any other way)
  • Optimize indexes.
  • Improved usability and look-and-feel of the application

So go take a look at the changes at http://trac.sitecore.net/IndexViewer 

If you want to see some screenshots of the new features, take a look here

What I would like to add next, is extended search functionality.

Standard
New releases, podcast, Sitecore

Sitecore podcast launched

Over at Learn Sitecore my coworker Jimmi Lyhne Andersen and I have just launched a brand new Sitecore podcast. Hopefully you will all like it and hopefully it will bring more article contributors to Learn Sitecore.

In the first episode we interview Sitecore CTO John West. We talk about Dreamcore and Sitecore in general. Check it out at: http://learnsitecore.cmsuniverse.net/en/podcasts.aspx

Enjoy!

Standard
Analytics, OMS, Sitecore

Will Sitecore OMS end strictly hierarchical sites?

Since the release of Sitecore OMS there have been much hype about the product and many people have speculated on what impact it will have on the CMS industry. However – in my opinion – the product has been more or less misunderstood or at least underestimated. Partly the product has been considered as a (somewhat limited) analytics tool and partly as a marketing tool allowing multivariate testing, conditional renderings etc. This is the result of several factors; one of them being that people review the product, without having understood the concept; another being that the product has been marketed for marketers. Therefore attention has been given on presentation and conditional renderings, when discussing personalization or behavioral targeting. Every demo I have seen have revolved around presentations and how they can vary depending on the profile of the website user or how a non technical marketer can act upon analytics data directly without the developer being involved.

To be honest I think this is somewhat unambitious considering the power of the product. Sitecore has always excellented in focusing on keeping presentation as layer on top of the content. The demos I have seen have focused on the presentation layer strictly. This is all fine and I find the options given to the non-technical personal impressive, but in my opinion the product has a lot more to offer than that. I think that we in the future will see the analytics, personalization etc. applied to content as well as the presentation.

The past – hierarchical sites

So what do I mean by this? Well, most of the sites I work on, the real resource on the site is good and relevant content. The issue is then how do we present and structure this best for the user of the site? (Well most of the time this is the issue; I have actually worked with clients who think the most important job is to structure the content well for the content authors.) Anyway the focus on the information architecture and structure has always been inwards and out and how the content authors can deliver the content in the right structure.

This is the case of a hierarchical site. In these types of sites content authors try to force the content into a hierarchy, which dimensions often are dictated by the design of the navigation parts on the frontend. However content is rarely strictly hierarchical. Content is often more relational and is relevant in multiple places in the hierarchy and should be presented several places. If this doesn’t happen automatically the content authors will have a lot of maintenance and will have to consider where content should be presented on the frontend each time they create it. Further the hierarchy often resembles something that the website users don’t know anything about – such as the organizational structure of the company. So hierarchical sites tend to be hard to maintain and the users of the website are more often than not, going to have problems finding the content they are looking for. (A great example is the SDN. Who can find something on that site without using the search functionality?)

The present – Taxonomy driven websites

To accommodate this issue we have seen more and more request for taxonomy driven sites and have implemented them with success. In these types of sites the navigation of the site is controlled by tags. Content is created centrally by the content authors and they will have to tag the content with terms indicating what the content is about. The content is then automatically shown relevant and often multiple places on the site, depending on how the hierarchy of the tags is structured.

The limitation of this is still that the approach is inwards and out. The content authors and the information architects still have to create the hierarchy based on the presumptions about the users.

The future – behavior driven websites

And this is where OMS comes into the picture. Imagine if we could construct sites, which are completely outwards and in. The information shown on the websites is structured by how the users behave and not by what the content authors think is a good structure. The information OMS has gathered about the each user can be used and he will automatically be presented for relevant content based on previous experiences with similar profiles. Further imagine that the web analysts and marketers can create goals in OMS and then the content structure on the site will change, so that it will present the structure which gives the most conversions based on the behavior of other users or profiles, which have made a conversion. I call this a behavior-driven website and I would love to be given the opportunity to implement it.

So what is the difference from what we have already heard about the product? In my opinion personalization, behavioral targeting etc. should be based at content level and not only at presentation level. For instance take the functionality for A/B testing. This is based on different presentations, but in a behavior-driven website the A/B testing is applied to the content – in Sitecore that would be an Item. Imagine creating two versions of an item and then test the different content to see which brings most conversions. Imagine that the hierarchy of the site isn’t based on organization structure or tags defined by the authors, but from whatever structure bring most conversions for the profile the user matches. This can’t be handled in presentations – only at content level. Imagine that content authors never need to worry about where content should be placed, it is automatically placed where analytics from real users says is the best place. Now this would really be cool and I am sure it can be achieved with OMS and that is why having live analytics data together with your CMS is going to change how we build sites… Or so I hope 🙂

Does this make sense outside my brain?

Standard