首页 > Web开发 > 详细

AutoBundleWeb

时间:2015-08-15 01:32:05      阅读:340      评论:0      收藏:0      [点我收藏+]
using System;
using System.Web;
using System.Web.Optimization;

namespace AutoBundleWeb
{
    public static class ScriptsBundle2
    {
        public static IHtmlString Bundle2(params string[] paths)
        {
            string path = RegisterBundles(paths);
            return Scripts.RenderFormat(Scripts.DefaultTagFormat, path);
        }

        private static string RegisterBundles(params string[] paths)
        {
            var key = Math.Abs(string.Join(null, paths).GetHashCode());
            string virtualPath = string.Format("~/bundles/" + key);

            var bundle = BundleTable.Bundles.GetBundleFor(virtualPath);
            if (bundle == null)
            {
                var scriptBundle = new ScriptBundle(virtualPath);
                scriptBundle.Include(paths);
                BundleTable.Bundles.Add(scriptBundle);
            }

            return virtualPath;
        }
    }
}


    @ScriptsBundle2.Bundle2("~/Scripts/bootstrap.js", "~/Scripts/respond.js")

demo download

 

 

AutoBundleWeb

原文:http://www.cnblogs.com/chinaniit/p/4731617.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!