# 'jQuery' is undefined

**URL:** <https://community.miniprofiler.com/t/jquery-is-undefined/24>\
**Category:** .NET\
**Created:** [June 20, 2013, 2:45am UTC](https://community.miniprofiler.com/t/jquery-is-undefined/24 "2013-06-20T02:45:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anpv](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@anpv](https://community.miniprofiler.com/u/anpv)\
**Post date:** [June 20, 2013, 2:45am UTC](https://community.miniprofiler.com/t/jquery-is-undefined/24/1 "2013-06-20T02:45:31Z")

</div>

Hello!  
I use [ASP.NET](http://ASP.NET) MVC 4 project.  
Install package from Nuget MiniProfiler 2.1.0.  
Setup in main page razor view `@StackExchange.Profiling.MiniProfiler.RenderIncludes()` and in Global.asax Start/Stop.  
When load main page raise javascript error ‘jQuery’ is undefined.  
It occurs because first load script [http://localhost:62928/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=](http://localhost:62928/mini-profiler-resources/includes.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=)  
which contains jQuery call at 897 line `...function(){d.event.special[this]={add:h}})})(jQuery);`  
But JQuery loaded in next request [http://localhost:62928/mini-profiler-resources/jquery.1.7.1.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=](http://localhost:62928/mini-profiler-resources/jquery.1.7.1.js?v=xwYPDDH1blvqmxgsBweNC++H7CFU3KGQ+zFcVlJPsXw=)

---

<div class="post-metadata">

**Author:** ![anpv](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@anpv](https://community.miniprofiler.com/u/anpv)\
**Post date:** [June 20, 2013, 5:03pm UTC](https://community.miniprofiler.com/t/jquery-is-undefined/24/2 "2013-06-20T17:03:37Z")

</div>

In Visual Studio 2012 update 2 create new project: [ASP.NET](http://ASP.NET) MVC 4 Web Application.  
Add HomeController and Index view.  
Via NuGet install MiniProfiler.MVC3 package.  
In Index view before body tag add `@StackExchange.Profiling.MiniProfiler.RenderIncludes()`.  
Open Manage NuGet packages… -\> Updates (Stable only) and click Update All button.  
Rebuild solution.  
Run Ctrl+F5 and get error “Line: 895 Error: ‘jQuery’ is undefined”.

---

<div class="post-metadata">

**Author:** ![John](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@John](https://community.miniprofiler.com/u/John)\
**Post date:** [April 1, 2014, 3:15pm UTC](https://community.miniprofiler.com/t/jquery-is-undefined/24/3 "2014-04-01T15:15:43Z")

</div>

Is this an IE 8 issue?  
There is a fix involving wildcard mapping to aspnet\_isapi.dll for IIS.  
I’m not sure how to map against VS2012’s [ASP.NET](http://ASP.NET) development server…

---

<div class="post-metadata">

**Author:** ![John](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@John](https://community.miniprofiler.com/u/John)\
**Post date:** [April 4, 2014, 9:30pm UTC](https://community.miniprofiler.com/t/jquery-is-undefined/24/4 "2014-04-04T21:30:38Z")

</div>

Good news for my development machine, I’ve resolved this problem for my [ASP.NET](http://ASP.NET) Development Server… so far, so good…

I decided to implement MiniProfiler through an HTTP Module in my .NET web forms project, following the guidelines from here [http://www.codeproject.com/Articles/246820/Using-MVC-Mini-Profiler-as-a-Http-Module](http://www.codeproject.com/Articles/246820/Using-MVC-Mini-Profiler-as-a-Http-Module).

In order to solve the exception thrown due to not loading jQuery-1.7.1.js before MiniProfiler was invoked, I added the script to the insertions from the HTTP Module, just before the insertion of the MiniProfiler.Includes().ToHtmlString().

```
    private string MiniProfiler_jQuery = @"<script type=""text/javascript"" src=""Scripts/jquery-1.7.1.js""></script>";

```

Here is my ‘Write’ method in MiniProfilerFilterStream.cs that inserts the reference:

public override void Write(byte[] buffer, int offset, int count)  
{  
if (!profilerHtmlRendered)  
{  
var responseText = Encoding.UTF8.GetString(buffer, offset, count);

```
            if (responseText.Contains("</body>"))
            {
                var miniProfilerHtml = MiniProfiler.RenderIncludes().ToHtmlString();
                int index = responseText.IndexOf("</body>") + 8;
                int index2 = index + MiniProfiler_jQuery.Length + 1;
                var newOutput = responseText.Insert(index, MiniProfiler_jQuery).Insert(index2, miniProfilerHtml);
                var newBytes = Encoding.UTF8.GetBytes(newOutput);

                stream.Write(newBytes, 0, newBytes.Length);
                profilerHtmlRendered = true;
                return;
            }
        }

        stream.Write(buffer, offset, count);
    }
```
