Click here to Skip to main content
15,886,018 members
Articles / Web Development / CSS

Combres - WebForm & MVC Client-side Resource Combine Library

Rate me:
Please Sign up or sign in to vote.
4.50/5 (8 votes)
1 Nov 2009Apache13 min read 52.1K   3.1K   22  
A .NET library which enables minification, compression, combination, and caching of JavaScript and CSS resources for ASP.NET and ASP.NET MVC web applications. Simply put, it helps your applications rank better with YSlow and PageSpeed.
using System;
using System.Web;
using System.Web.Caching;
using System.Xml.Schema;

namespace Combres
{
    internal static class Configuration
    {
        private static readonly ConfigSectionSetting Config = ConfigSectionSetting.Create();
        private static readonly string CacheKey = string.Concat(typeof(Configuration).FullName,
            ".", DateTime.Now);

        /// <summary>
        /// Creates an instance of <see cref="Settings"/> based on the XML definition file.
        /// The result will be cached as long as the XML definition file isn't change.  If the 
        /// file is changed, a new instance will be created upon the next request.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">If <paramref name="context"/> is null</exception>
        /// <exception cref="XmlSchemaException">If there is any validation error in the 
        /// XML definition file.</exception>
        internal static Settings GetSettings(HttpContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            var settings = context.Cache[CacheKey] as Settings;
            if (settings == null)
            {
                /*
                 * The Cache object is thread-safe thus there won't be any data corruption.
                 * The code is not protected against multiple writes although due to the 
                 * huge amount of reads and limited number of writes, this no-lock approach 
                 * is likely to be more efficient than the use of lock.
                 */
                var filePath = context.Server.MapPath(Config.DefinitionUrl);
                settings = new ConfigReader().Read(filePath);   
                context.Cache.Insert(CacheKey, settings, new CacheDependency(filePath));
            }
            return settings;
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


Written By
Chief Technology Officer KMS Technology
Vietnam Vietnam
You can visit Buu's blog at http://www.buunguyen.net/blog to read about his thoughts on software development.

Comments and Discussions