简体   繁体   English

缩小signalr / hubs文件

[英]minify the signalr/hubs file

I'm using signalr in my app and am referencing it like so: 我在我的应用程序中使用signalr并且正如此引用它:

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

Of course signalr is generated javascript dynamically on the fly. 当然signalr是动态生成的javascript动态。 When I run yslow to better the performance of my web application it complains that singalr/hubs is not minified. 当我运行yslow来改善我的Web应用程序的性能时,它抱怨singalr / hubs没有缩小。 Surely when I click on the link it shows the js, small snippet sample: 当我点击链接时,它显示了js,小片段样本:

/*!
 * 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. 我还要澄清一下,我使用的是lcsk ,它可以在这里找到,它使用了signalr。 In this package there is a startup.cs file which looks like this: 在这个包中有一个startup.cs文件,如下所示:

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: SignalR hub.js缩小 (但这似乎是使用global.asax文件)而且我也看到了这个:

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

But I'm uncertain where I need to do any of this with what I have. 但我不确定我需要用我所拥有的东西做什么。

Check out the extensibility guide . 查看可扩展性指南 It lists an IJavaScriptMinifier interface you can implement to do what you're looking for. 它列出了一个IJavaScriptMinifier接口,您可以实现它以执行您正在寻找的内容。 (And maybe couple it with the Optimization/Bundling library or another 3rd party minifier). (也许可以将它与优化/捆绑库或其他第三方缩小器结合使用)。

As the extensibility guide suggests you should implement IJavaScriptMinifier which consists of just one Minify method. 正如可扩展性指南所示,您应该实现IJavaScriptMinifier由一个Minify方法组成的IJavaScriptMinifier 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. 然后,将您的IJavaScriptMinifier实现类提供给SignalR依赖注入管道 ,SignalR将在需要时使用minifier。

Here's an example of a class implementing IJavaScriptMinifier , where Minifier is the Microsoft Ajax Minifier . 下面是一个实现IJavaScriptMinifier的类的IJavaScriptMinifier ,其中MinifierMicrosoft Ajax Minifier

public class SignalrJavascriptMinifier : IJavaScriptMinifier
{
    public string Minify(string source)
    {
        return new Minifier().MinifyJavaScript(source);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM