Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does MiniProfiler load jquery-1.7.1 even though I've already loaded that on the page?

I've implemented the StackExchange MiniProfiler on a ASP.NET WebForms page which already references v1.7.1 of jQuery. The jQuery file is hosted locally, so my masterfile looks like this:

<script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<%= MiniProfiler.RenderIncludes() %>

However, when I view the source of the output generated, I get something similar to this

<script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">    
    ...
    load('/app/mini-profiler-resources/jquery.1.7.1.js?v=tNlJPuyuHLy/d5LQjyDuRbWKa0weCpmO3xkO6MH4TtA=', initMp);
</script>

Looking in the dev tools network tab, I can see that it's putting two requests in, one for Scripts/jquery-1.7.1.min.js and another for /app/mini-profiler-resources/jquery.1.7.1.js

Isn't this a fairly major redundancy issue? How do I stop the MiniProfiler includes from requesting, downloading and parsing another copy of the jQuery library?

like image 865
growse Avatar asked Apr 11 '12 11:04

growse


1 Answers

The reason is that we are loading jQuery in noConflict. This eliminates the risk of having jQuery versions clash. For example, we are not sure MiniProfiler will still work if jQuery version 1.0 is on the page. To avoid any risk, we load our own version.

Now, I am open to a pull request that does a version check on jQuery prior to requesting it, if the "right" version is there we can simply alias jQueryMP to jQuery. However, this complicates the code and only solves the issue for a single version of jQuery.

like image 95
Sam Saffron Avatar answered Nov 03 '22 01:11

Sam Saffron