Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling JavaScript code using MiniProfiler

MiniProfiler can log Ajax calls and display a breakdown of the timings.

Is it also possible to add custom steps to my JavaScript code?

like image 873
Karl Glennon Avatar asked Sep 29 '26 02:09

Karl Glennon


1 Answers

You can time client-side script execution time by using the TimeScript command in a Razor view.

Example from 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>

Here the time spent loading the jQuery and CSS scripts are being timed. You could of course inject any client-side code using this function.

like image 164
Yaakov Ellis Avatar answered Oct 01 '26 16:10

Yaakov Ellis