---
title: "Add reference of System.Web.Optimization in MVC 4"  
description: "In this article I tell you how to add reference of System.Web.Optimization in your existing application."  
author: "AVADHESH PATEL"  
published: 2013-01-29  
updated: 2019-12-12  
canonical: https://www.mindstick.com/articles/1131/add-reference-of-system-web-optimization-in-mvc-4  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 3 minutes  

---

# Add reference of System.Web.Optimization in MVC 4

System.Web.[Optimization](https://yourviews.mindstick.com/view/85459/what-is-conversion-rate-optimization-and-how-to-get-started) assembly required for using feature of Bundling in MVC 4. Bundling is used for managing JavaScript and CSS files. You can read more information about Bundling form below link.\

[https://www.mindstick.com/Articles/1086/bundling-and-minification-in-asp-dot-net-mvc-4](https://www.mindstick.com/Articles/1086/bundling-and-minification-in-asp-dot-net-mvc-4)\

In this article I tell you how to [add reference](https://www.mindstick.com/forum/548/how-to-add-reference-to-system-web-optimization) of System.Web.Optimization in your existing application.\

Note: When you open MVC 4 Application with “Internet Application” option than System.Web.Optimization assembly by default added in [your application](https://answers.mindstick.com/qa/95487/how-do-you-troubleshoot-when-your-application-link-is-not-responding). But, if you open application with “Empty” option than “Are you missing an assembly reference?” [Error message](https://www.mindstick.com/forum/23174/error-message-the-page-you-are-requesting-cannot-be-served-because-of-the-extension-configuration) come when you use System.Web.Optimization namespace.

Step 1: Open [Package Manager](https://answers.mindstick.com/qa/112022/what-are-the-advantages-of-using-a-package-manager-like-npm-or-yarn-in-javascript-development) Console from View menu, as below image (Figure 1).

##### Figure 1:

![Add reference of System.Web.Optimization in MVC 4](https://www.mindstick.com/mindstickarticle/e9e9a790-9f3f-4b8b-ad5d-9fdcef53a05c/images/32b16a0b-60be-497b-b686-87622e42dd41.png)

Step 2: Package Manager Console [command prompt](https://answers.mindstick.com/qa/51716/how-to-make-bootable-pendrive-using-cmd-windows-command-prompt) will be display at bottom of [Visual Studio](https://www.mindstick.com/articles/12378/visual-studio-for-mac-is-out-of-beta-preview-now-officially-available) as below image (Figure 2).

##### Figure 2:

![Add reference of System.Web.Optimization in MVC 4](https://www.mindstick.com/mindstickarticle/e9e9a790-9f3f-4b8b-ad5d-9fdcef53a05c/images/b2a2018c-e5d1-41a9-a538-a2de9c82885c.png)

Step 3: Paste below line of code in Package Manager Console prompt and press enter [button as](https://answers.mindstick.com/qa/32548/do-you-ever-use-the-favorite-button-as-a-bookmark-on-twitter) below image (Figure 3).

```
Install-Package Microsoft.Web.Optimization –Pre
 
OR
 
Install-Package Microsoft.Web.Optimization
```

Figure 3:

![Add reference of System.Web.Optimization in MVC 4](https://www.mindstick.com/mindstickarticle/e9e9a790-9f3f-4b8b-ad5d-9fdcef53a05c/images/15f9b929-391f-4f54-bfc6-1488798bf42e.png)

Step 4: Wait for few minutes. When System.Web.Optimization downloaded and added in your application than [confirmation message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net) will be display as below image (Figure 4).

##### Figure 4:

![Add reference of System.Web.Optimization in MVC 4](https://www.mindstick.com/mindstickarticle/e9e9a790-9f3f-4b8b-ad5d-9fdcef53a05c/images/7fcde95e-3f59-4e18-8e98-00b6e9de549b.png)

Step 5: Now, add one class in App_Start folder and give name BundleConfig as below image (Figure 5).

##### Figure 5:

![Add reference of System.Web.Optimization in MVC 4](https://www.mindstick.com/mindstickarticle/e9e9a790-9f3f-4b8b-ad5d-9fdcef53a05c/images/0d57477b-5620-4cf2-bf97-0422433afa79.png)

Step 6: Include the Optimization namespace and give the path of JavaScript and CSS within BundleConfig class as below line of code

```
using System.Web.Optimization;
 
namespace AddReference
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/Scripts/js").Include(
                "~/Scripts/jQuery.1.7.1.js",
                "~/Scripts/comboboo.js")
            );
 
            bundles.Add(new StyleBundle("~/Style/css").Include(
                 "~/Style/comboboo.css",
                 "~/Style/updates.css")
            );
        }
    }
}
```

Step 7: Include the Optimization namespace and call RegisterBundles () function in Application_Start () in your global.asax.cs as below line of code.

```
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Optimization;
 
namespace AddReference
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
 
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }
}
```

Step 8: Include the Optimization namespace and render the bundle(s) in your view page as below line of code

```
@using System.Web.Optimization
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <title>Index</title>
    @Scripts.Render("~/Scripts/js")
    @Scripts.Render("~/Style/css")
</head>
<body>
    <div>
    </div>
</body>
</html>
```

Note: Build and Save application and press F5 key for execution and see View Source of page and check included JavaScript and CSS file.

\

---

Original Source: https://www.mindstick.com/articles/1131/add-reference-of-system-web-optimization-in-mvc-4

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
