Javascript ASP.NET MVC中JS和CSS的组合和缩小

Javascript ASP.NET MVC中JS和CSS的组合和缩小,javascript,asp.net-mvc,minify,Javascript,Asp.net Mvc,Minify,我创建了默认的ASP.NETMVC3Web应用程序。然后我在\Views\Shared\u Layout.cshtml视图中添加了三个css和三个js文件: <!DOCTYPE html> <html> <head> <title>@ViewBag.Title</title> <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type=

我创建了默认的ASP.NETMVC3Web应用程序。然后我在\Views\Shared\u Layout.cshtml视图中添加了三个css和三个js文件:

<!DOCTYPE html>
<html>
<head>
    <title>@ViewBag.Title</title>
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/StyleSheet1.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/StyleSheet2.css")" rel="stylesheet" type="text/css" />

    <script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/JScript1.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/JScript2.js")" type="text/javascript"></script>

</head>
<body>
    <div class="page">
        <div id="header">

@视图包。标题

当我运行应用程序时,我发现html代码是

<!DOCTYPE html>
<html>
<head>
    <title>Home Page</title>
    <link href="/Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="/Content/StyleSheet1.css" rel="stylesheet" type="text/css" />
    <link href="/Content/StyleSheet2.css" rel="stylesheet" type="text/css" />

    <script src="/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="/Scripts/JScript1.js" type="text/javascript"></script>
    <script src="/Scripts/JScript2.js" type="text/javascript"></script>

</head>
<body>
    <div class="page">

主页
是否可以在MVC中使用处理程序将我的输出html更改为:

<!DOCTYPE html>
    <html>
    <head>
        <title>Home Page</title>
        <script src="js.axd=/Scripts/jquery-1.5.1.min.js,/Scripts/JScript1.js,/Scripts/JScript2.js" type="text/javascript"></script>
        <link href="css.axd=/Content/Site.css,/Content/StyleSheet1.css,/Content/StyleSheet2.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div class="page">

主页
因此链接
js.axd=/Scripts/jquery-1.5.1.min.js、/Scripts/jscript.js、/Scripts/jscript.js
将所有这些js文件的内容返回到浏览器,并且link
css.axd=/content/Site.css、/content/StyleSheet1.css、/content/StyleSheet2.css
将返回所有css文件的内容

我以前在IHttpHandler的ASP.NET中做过一些事情,但不知道如何在MVC中做到这一点,因为我只是MVC的初学者

任何帮助和代码示例都将不胜感激。
谢谢大家!

您可以使用bundle和minification nuget包

在NuGet控制台键入:“安装包Microsoft.AspNet.Web.Optimization”

示例如下:

我在自己的项目中使用。此外,此列表包含Nuget中的前20名