2

My app is using a SignalR 1.1.2 on ASP.NET MVC It has the following call in the View

This uses the auto-generated hub. At this point all client and server side methods are done.

Can I get a copy of the 'hubs.js' file I get when I paste this link into the browser.

I want to add a new javascript file to the BundleConfig.cs so I can minify this file and try and improve the performance of my app.

Hope someone can advise, I have done it and it seems to work, I just want to be sure that I will not loose the ability to shift gears to websockets, SSE, Forever-Frame depending on what the client and server can negotiate.

matthewbaskey
  • 1,027
  • 2
  • 17
  • 40

2 Answers2

2

MVC web optimization does not support dynamic scripts. I did it like this in my last project, it doesnt help with minifying but you can add the static script to the bundle config

(function ($) {
    var dynamicScripts = ["signalr/hubs", "eventAggregation/events"];
    $.each(dynamicScripts, function () {
        $.ajax({
            url: this,
            cache: true,
            dataType: "script",
            async: false
        });
    });
} (jQuery));
Anders
  • 17,306
  • 10
  • 76
  • 144
  • Very interesting bit of code. I didn't know ajax could have a dataType of 'script'. I have used the cache attribute but never used with this dataType. What about the async attribute, what if it were true, might this help stop any ui threads from blocking? – matthewbaskey Feb 27 '14 at 10:01
  • It will use the same type of caching as for static JS files – Anders Feb 27 '14 at 12:10
  • so you put this bit of code into a static script file and then add this file to the bundler? – matthewbaskey Feb 27 '14 at 14:06
1

if you navigate to the /signalr/hubs uri you can save this javascript file and put it in a bundle. Of course if you change anything to do with signalr then it might not work. But this is for release. Just a note that this 1.1.2

matthewbaskey
  • 1,027
  • 2
  • 17
  • 40