ravendb/ravendb — pull request #496 by ToshB (2012-12-02 14:59:23+00:00)
Title: Mvc Profiler isolation

## A somewhat big rewrite/restructuring of the MvcProfiler JS code

### Reasons for doing this, in descending order of annoyance
- When loading MvcProfiler it gives warnings in the Chrome developer console due to the way yepnope.js (the original MvcProfiler loader) loads resources.
- My own instance of jQuery is modified by the loading of jQuery template, so MvcProfiler was not as non-intrusive as I'd like it to.
- jQuery tmpl sometimes throws an error, causing MvcProfiler loading to fail. (Also, this plugin never made it out of beta, and is no longer in active development or maintenance)
- Loading profiler causes 10 additional file loads, in addition to requests to load profiling data, which is undesirable noise when inspecting network requests.
- The existing profiler JavaScript was complex and hard to build on

### What I suggest
- Use Require.js script loader, which loads scripts without warnings in addition to limiting global variables to a minimum. It also simplifies referencing other script files.
- Use Backbone.js for separating models and views, this significantly improves readability and maintainability of MvcProfiler. This includes splitting up logic into separate files.
- Use noConflict() on jQuery, Backbone and Underscore to prevent polluting the global namespace.
- Use Require.js optimizer to concatenate and minify all js-files and templates into one file, which reduces the number of requests to load MvcProfiler to 2 (js+css), plus profiling data requests.

#### Other notes

Require.js is namespaced to 'ravenprofiler' to prevent interference with existing Require.js scripts.
Optimization is done as a Pre-Build event by using Require.js Optimizer through node.exe, which is included in js/build-folder.

As this uses an isolated instance of jQuery, and adds an ajaxCompleted-handler to the global jQuery-object if it exists, MvcProfiler needs to be loaded after jQuery on the hosting page, for instance as the last thing in body.

I have not changed much of the html and styling, to limit the changes to a minimum. One thing I removed was a reference to Context.Controller and Context.Action in the "Request header html" which as far as I could tell was never set. There are a few other things that can be done here like adding only one element to the DOM in addition to more elegant handling of Request Details popups.

File size is increased, due to jQuery, Backbone, Underscore and Require being included, but is is still imho ok. The optimized script file could be served with more aggresive cache headers, but this should only be done after adding version number to the script file to bust caches between versions.