在构建时在JavaScript中连接和缩小JavaScript - ASP.NET MVC [英] Concatenate and minify JavaScript on the fly OR at build time - ASP.NET MVC

查看:181
本文介绍了在构建时在JavaScript中连接和缩小JavaScript - ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为此问题的扩展,此处在用户控件中链接JavaScript库我之前是一些例子,说明人们如何在运行或构建时间连接和缩小JavaScript。我也想看看它如何工作到你的母版页。

As an extension to this question here Linking JavaScript Libraries in User Controls I was after some examples of how people are concatenating and minifying JavaScript on the fly OR at build time. I would also like to see how it then works into your master pages.

我不介意页面特定的文件被缩小和链接在当前, ),但主母版页上的所有JavaScript文件(我有大约5或6)我想连接和缩小。

I don't mind page specific files being minified and linked inidividually as they currently are (see below) but all the JavaScript files on the main master page (I have about 5 or 6) I would like concatenated and minified.

和缩小! : - )

当前母版页包含我想要拼接和缩小的常见JavaScript文件:

Current master page with the common JavaScript files that I would like concatenated and minified:

<%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %>
<head runat="server">
    ... BLAH ...
    <asp:ContentPlaceHolder ID="AdditionalHead" runat="server" />
    ... BLAH ...
    <%= Html.CSSBlock("/styles/site.css") %>
    <%= Html.CSSBlock("/styles/jquery-ui-1.7.1.css") %>
    <%= Html.CSSBlock("/styles/jquery.lightbox-0.5.css") %>
    <%= Html.CSSBlock("/styles/ie6.css", 6) %>
    <%= Html.CSSBlock("/styles/ie7.css", 7) %>
    <asp:ContentPlaceHolder ID="AdditionalCSS" runat="server" />
</head>
<body>
    ... BLAH ...
    <%= Html.JSBlock("/scripts/jquery-1.3.2.js", "/scripts/jquery-1.3.2.min.js") %>
    <%= Html.JSBlock("/scripts/jquery-ui-1.7.1.js", "/scripts/jquery-ui-1.7.1.min.js") %>
    <%= Html.JSBlock("/scripts/jquery.validate.js", "/scripts/jquery.validate.min.js") %>
    <%= Html.JSBlock("/scripts/jquery.lightbox-0.5.js", "/scripts/jquery.lightbox-0.5.min.js") %>
    <%= Html.JSBlock("/scripts/global.js", "/scripts/global.min.js") %>
    <asp:ContentPlaceHolder ID="AdditionalJS" runat="server" />
</body>

在这样的页面中使用(我很高兴):

Used in a page like this (which I'm happy with):

<asp:Content ID="signUpContent" ContentPlaceHolderID="AdditionalJS" runat="server">
    <%= Html.JSBlock("/scripts/pages/account.signup.js", "/scripts/pages/account.signup.min.js") %>
</asp:Content>


UPDATE:现在的建议(2013年底):

UPDATE: Recommendations for now (late 2013):

我将看一下Microsoft ASP.NET内置的 Bundling and Minification

I would look at Microsoft ASP.NET's built in Bundling and Minification.

推荐答案

Professional ASP.NET 3.5 的附录中Scott Hanselman谈论 Packer for .NET 。这将与MSBuild集成和打包生产部署的javascript文件等。

In the appendix of Professional ASP.NET 3.5 Scott Hanselman talks about Packer for .NET. This will integrate with MSBuild and pack javascript files for production deployments etc.

这篇关于在构建时在JavaScript中连接和缩小JavaScript - ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆