Why You Need Them and How to Use Them
The site definition process in SharePoint is complex, but very flexible. Techniques such as “ghosting” can save you a lot of server space and beef up performance. But you need to understand when and how to use site definitions in order to avoid unintended consequences down the line.
SharePoint makes developing templates easy. You simply create a site the way that you want it and then save it as a template, quickly and easily freezing the site setup into a reusable stamp that you can then use to create other sites. However, user templates in SharePoint can lead to performance problems and may not be the best approach if you’re trying to create a set of reusable templates for an entire organization. Instead, you should use site definitions to create templates that form the basis for creating new sites. The site definitions approach doesn’t suffer from the same limitations as user templates.
Understanding Ghosting and Unghosting before diving into site definitions it’s important to understand one of the inner workings of SharePoint. When you create a new site, SharePoint doesn’t really copy the pages for that site— default.aspx and so on—into a new database table or directory. These files exist once and only once on each of the front end Web servers. Instead, SharePoint creates a reference to those files in the database tables that define the new site, a process called “ghosting.” The outcome is that the site appears to have its own unique pages, but the pages are actually shared across all sites that use the same definition. This has two distinct advantages over copying the files to each site individually when the site is created. First, it saves space. If you have a thousand sites, rather than having a thousand copies of a file you still have only one. Second, it improves performance. Instead of having to load and cache a thousand pages from the database, the server needs to cache only one copy from the file system, which can improve performance by freeing cache memory for other purposes. Loading the file from the Web server’s local file system improves performance by eliminating the overhead of the database call and the network traffic to the database.
One interesting benefit of this approach is that when you make a change to one file on the file system, that change takes effect across all the sites that have been created. All in all, the process of ghosting is a huge benefit to SharePoint.
However, there are some limitations.
SharePoint can’t ghost every page. Some operations, such as editing a page in Designer, cause SharePoint to “unghost” dependent pages for the site. Because ghosting requires all ghosted pages to be exactly the same across all the sites that share them, SharePoint unghosts, or creates a copy of the page in the database, whenever a ghosted page changes, for example, when someone performs an edit operation on the page. Unghosting lets users customize their own sites without impacting other users who might be using the same file. Unfortunately however, unghosting also has a negative performance impact, and makes global changes, such as applying corporate branding to the entire collection of sites far more difficult. Unghosting is the primary reason why efforts to leverage the power of site definitions to change the branding of an entire site may not work as intended.