示例#1
0
        /// <summary>
        /// load the Page.Items's script
        /// </summary>
        /// <param name="page"></param>
        public static void LoadStyle(Page page)
        {
            List <string> styleList = page.Items["StyleList"] as List <string>;

            if (styleList != null)
            {
                bool optimizeStyle = ConfigurationManager.AppSettings["OptimizeStyle"] == "1";
                if (optimizeStyle)
                {
                    // cache the style if not cached already
                    PageHelpers.Cache(CacheFactory.CreateStyleCache(), styleList);
                    string url = string.Format("{0}?hash={1}",
                                               page.ResolveClientUrl("~/StyleOptimizer.ashx"),
                                               HttpUtility.UrlEncode(PageHelpers.GetHash(styleList)));
                    AddStyleToPage(page, url);
                }
                else
                {
                    foreach (string styleUrl in styleList)
                    {
                        AddStyleToPage(page, styleUrl);
                    }
                }
            }
        }
示例#2
0
        public void ProcessRequest(HttpContext context)
        {
            HttpRequest request = context.Request;

            string hash = request["hash"];

            if (!string.IsNullOrEmpty(hash))
            {
                ICache cache         = CacheFactory.CreateStyleCache();
                string keyName       = PageHelpers.GetCacheKey(hash);
                byte[] responseBytes = cache.Get <byte[]>(keyName);
                if (responseBytes != null)
                {
                    HttpResponse response = context.Response;

                    response.AppendHeader("Content-Length", responseBytes.Length.ToString(CultureInfo.InvariantCulture));
                    response.ContentType = "text/css";
                    response.Cache.SetCacheability(HttpCacheability.Public);
                    response.Cache.SetExpires(DateTime.Now.Add(TimeSpan.FromDays(30)));
                    response.Cache.SetMaxAge(TimeSpan.FromDays(30));
                    response.Cache.AppendCacheExtension("must-revalidate, proxy-revalidate");

                    response.OutputStream.Write(responseBytes, 0, responseBytes.Length);
                }
            }
        }