Possible to include scripts in js/plugins and then route through _main.js?

Hey guys.

I wonder if it is possible to add an external javascript file in js/plugins, run grunt (compress, hint, etc) and then “route” (meaning load script on specific pages) through _main.js? I looked in a little on how it could be done, I think it would be possible to assign the external script to the global namespace for example Jquery and then load it inside _main.js is this possible? I just looking in to getting started working with _main.js, but I believe it would get quite hard to manage after a while, with so manny script in one place.

Providing you reference it properly, you can access any namespace (including global) from _main.js.

So a jQuery function would be called with $.fn.myFunction();, a custom namespace would be customNamespace.myFunction(); and a globally declared function would just be myFunction();,

(function($){
  $.fn.myFunction = function() {
    return alert('jQuery namespace');
  }; 
})(jQuery);

var customNamespace = {
  myFunction: function() {
    alert('custom namespace');
  }
};

function myFunction() {
  alert('global namespace');
};