Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

minify the signalr/hubs file

I'm using signalr in my app and am referencing it like so:

<script src="/signalr/hubs" type="text/javascript"></script>

Of course signalr is generated javascript dynamically on the fly. When I run yslow to better the performance of my web application it complains that singalr/hubs is not minified. Surely when I click on the link it shows the js, small snippet sample:

/*!
 * ASP.NET SignalR JavaScript Library v2.1.1
 * http://signalr.net/
 *
 * Copyright Microsoft Open Technologies, Inc. All rights reserved.
 * Licensed under the Apache 2.0
 * https://github.com/SignalR/SignalR/blob/master/LICENSE.md
 *
 */

/// <reference path="..\..\SignalR.Client.JS\Scripts\jquery-1.6.4.js" />
/// <reference path="jquery.signalR.js" />
(function ($, window, undefined) {
    /// <param name="$" type="jQuery" />
    "use strict";

    if (typeof ($.signalR) !== "function") {
        throw new Error("SignalR: SignalR is not loaded. Please ensure jquery.signalR-x.js is referenced before ~/signalr/js.");
    }

    var signalR = $.signalR;

    function makeProxyCallback(hub, callback) {
        return function () {
            // Call the client hub method
            callback.apply(hub, $.makeArray(arguments));
        };
    }

    function registerHubProxies(instance, shouldSubscribe) {
        var key, hub, memberKey, memberValue, subscriptionMethod;

How can I minify this file if it is generated automagically?

Edit

Let me also clarify I am using lcsk which can be found here, which uses signalr. In this package there is a startup.cs file which looks like this:

using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(RIMS.LCSK.Startup))]

    namespace RIMS.LCSK
    {
        public class Startup
        {
            public void Configuration(IAppBuilder app)
            {
                app.MapSignalR();
            }
        }
    }

Do I need to somehow tell it to minify at this point? I've seen this:

SignalR hub.js minify (but this seems to be using a global.asax file) And I've also seen this:

https://github.com/SignalR/SignalR/issues/2403

But I'm uncertain where I need to do any of this with what I have.

like image 847
JonH Avatar asked Jul 08 '15 19:07

JonH


2 Answers

Check out the extensibility guide. It lists an IJavaScriptMinifier interface you can implement to do what you're looking for. (And maybe couple it with the Optimization/Bundling library or another 3rd party minifier).

like image 170
Brad Christie Avatar answered Nov 03 '22 08:11

Brad Christie


As the extensibility guide suggests you should implement IJavaScriptMinifier which consists of just one Minify method. Afterwards, provide your IJavaScriptMinifier implementing class to the SignalR dependency injection pipeline and SignalR will take care of using the minifier when it needs to.

Here's an example of a class implementing IJavaScriptMinifier, where Minifier is the Microsoft Ajax Minifier.

public class SignalrJavascriptMinifier : IJavaScriptMinifier
{
    public string Minify(string source)
    {
        return new Minifier().MinifyJavaScript(source);
    }
}
like image 1
Jorge Cabot Avatar answered Nov 03 '22 08:11

Jorge Cabot