2015-09-14 49 views
3

我想知道捆绑和缩小在服务器上运行的时间有多可能?ASP.NET捆绑和缩小。每个请求运行一次?

是否每个HTML请求都有一次? 每个浏览器会话一次? 每次应用程序部署一次?当应用程序被部署或重新启动,当Application_Start方法被称为在Global.asax.cs

由于创建

+0

每次应用池回收 – ediblecode

回答

3

束。在Application_Start内部,BundleConfig.RegisterBundles被调用,这实际上是魔术发生的地方。

public class MvcApplication : System.Web.HttpApplication 
{ 
    // this method is called on application start 
    protected void Application_Start() 
    { 
     AreaRegistration.RegisterAllAreas(); // registers areas 
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); // registers filters 
     RouteConfig.RegisterRoutes(RouteTable.Routes); // registers routes 
     BundleConfig.RegisterBundles(BundleTable.Bundles); // this generates the bundles 
    } 
} 

而在你BundleConfig.cs文件时,RegisterBundles方法是调用来创建方法,该束。

public class BundleConfig 
{ 
    public static void RegisterBundles(BundleCollection bundles) 
    { 
     // this is actually what's creating the bundles 
     bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
        "~/Scripts/jquery-{version}.js")); 
     // etc... 
    } 
} 

然后把它们存储在内存中,可以在/bundles/bundlename?v=versionId访问,并担任每个HTTP请求,但捆绑和微小的实际过程只发生一次。

2

捆绑微小的Application_Start注册运行一次,结果被缓存在服务器上。缓存版本提供了其他请求。 Aplication_Start在请求第一个资源时触发。