2012-08-13 70 views

回答

4

您可以通过在剃须刀视图中使用TimeScript命令来计算客户端脚本执行时间。从Sample.MVC

实施例:

<head> 
    @this.InitClientTimings() 
    @this.TimeScript("jQuery 2.0.3", @<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js" type="text/javascript"></script>) 

    @using (profiler.Step("<head> rendering")) 
    { 
    <title>@ViewBag.Title - MVC MiniProfiler Demo</title> 
    @(this.TimeScript("Our CSS", @<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />)) 
    @RenderSection("head", required:false) 
    } 
</head> 

这里所用的时间加载jQuery和CSS脚本被定时。您当然可以使用此功能注入任何客户端代码。