With the new version 8.1 of Sitecore we get a some really nice new features that’s been talked about a lot over the last few weeks. In this post I’d like to highlight one of the minor changes that I think is well worth spreading as well, since it makes life a bit easier for us developers.
The web.config file in a default Sitecore solution is really big and over the past years it has actually grown close to its maximum of 250kB file size. Most configuration in Sitecore can also be patched, but things outside the
<sitecore> element cannot be patched as easily. With almost all solutions we need to do at least small changes to the web.config outside the
<sitecore> scope, so that means we’ll have to include the web.config in our source code repositories.
You probably already know that having a clear strategy of dividing configs is key to make a solution easier to maintain. Your changes to the config should be clearly separated from the default config that Sitecore provides, so that you can let Sitecore maintain the default config as patches and updates are applied to the solution. 3rd party modules (should) also have their separate config and you should keep yours separate as well.
So the huge web.config file isn’t very elegant and can of course cause some trouble when upgrading Sitecore etc, since we typically have to include it in our code repositories. We want to keep it as small as possible. The first thing I’ve always done with every new instance of Sitecore, is to extract the majority of the web.config into a stand alone Sitecore.config file that I place in the App_Config folder and reference it in the sitecore section. This reduces the ~245kB file to ~25kB on a Sitecore 8.0 instance. I’ve been doing this for years.
So it was really about time Sitecore did something about this, and I was really happy to find that in 8.1, Sitecore have done this in the exact same way. Yes! In addition, Sitecore has also moved the log4net section from web.config into the Sitecore.config, so now we can patch the log4net config as well. Nice!
At last, I’d like to send a little message to Sitecore support: Please don’t ask us to do modifications in the config files. Tell us to patch it with a separate config file instead. I believe you’re working on this already, since it seems like you’ve improved on this over the last year, but I sometime still get the suggestion to modify a config file. I would never go on and actually do that myself, but others may do. Embrace good config structure and patch it instead.
Let’s keep config files well structured and maintainable.