If you're unsure if this is the solution you're looking for, ASP.NET 4.5 automatically handles bundling and minification when deploying your website in non-debug mode:
Within the ~/App_Start/BundleConfig.cs file, you define the bundles:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/all").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery.validate*",
"~/Scripts/bootstrap.js",
"~/Scripts/respond.js"));
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
}
In your ~/Views/Shared/_Layout.cshtml, you reference the specified bundles:
<html>
<head>
<!-- other head declarations -->
<!-- use the css bundle -->
@Styles.Render("~/Content/css")
</head>
<body>
<!-- other body declarations -->
<!-- use the javascript bundle -->
@Scripts.Render("~/bundles/all")
</body>
</html>
Upon Publishing your ASP.MVC site in the Release configuration, the CSS and JavaScript will be bundled and minified into single files.
- The CSS file will be accessed through something like: /Content/css?VoSYW5j1afpgB_oENS5Bi.
- The JavaScript file will be accessed through something like: /bundles/all?zWZPUr7GJrRS_Ux89ubfE81
Hash strings are utilized to prevent caching between builds.
You can find a comprehensive guide here, it's definitely worth checking out.