码迷,mamicode.com
首页 > Web开发 > 详细

AutoBundleWeb

时间:2015-08-15 01:35:02      阅读:167      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!