seajs的动态压缩

来源:互联网 发布:网络安全技术与应用 编辑:程序博客网 时间:2024/06/05 14:43
base: '/Bundle/js/',comboSyntax: ['?', ','],当运行seajs配置问题后,会启动响请求,Bundle控制器,去压缩js文件#region js压缩合并        class CacheItem        {            public string Content { set; get; }            public DateTime Expires { set; get; }        }        [HttpGet]        [IsPostedFromThisSite]        [CacheFilter(CacheProfile = "DefaultLong")]        public ActionResult js(string path, string v)        {            string tail = Request.QueryString[null];            string cacheKey = path + tail;            CacheItem cacheItem = HttpRuntime.Cache.Get(cacheKey) as CacheItem;//服务端缓存            if (cacheItem == null)            {                path = "~/Scripts/" + path;                StringBuilder notMinifiedJs = new StringBuilder();                string tempfile = Server.MapPath(path);                if (IO.File.Exists(tempfile))                {                    notMinifiedJs.Append(IO.File.ReadAllText(tempfile, Encoding.UTF8));                }                else                {                    if (tail != null)                    {                        foreach (var item in tail.Split(new string[] { ",", ";", "|" }, StringSplitOptions.RemoveEmptyEntries))                        {                            string temppath = Server.MapPath(path + item);                            if (IO.File.Exists(temppath))                            {                                notMinifiedJs.Append(IO.File.ReadAllText(temppath, Encoding.UTF8));                            }                        }                    }                }                var minifier = new Minifier();                var minifiedJs = minifier.MinifyJavaScript(notMinifiedJs.ToString(), new CodeSettings                {                    EvalTreatment = EvalTreatment.MakeImmediateSafe,                    PreserveImportantComments = false                });#if !DEBUG                cacheItem = new CacheItem() { Content = minifiedJs, Expires = DateTime.Now.AddDays(1) };                HttpRuntime.Cache.Insert(cacheKey, cacheItem, null, cacheItem.Expires, TimeSpan.Zero);#endif                return JavaScript(minifiedJs);            }            else            {                return JavaScript(cacheItem.Content);            }        }        #endregion
0 0