0

I'm trying to use the bundling features of System.Web.Optimization to minify my css and java script.

I have installed the pre release via NuGet

Install-Package Microsoft.Web.Optimization -Pre

and added the following references to my web.config files

/Views/Web.config

<pages pageBaseType="System.Web.Mvc.WebViewPage">
  <namespaces>
    .....
    <add namespace="System.Web.Optimization" />
  </namespaces>
</pages>

/Web.config

<pages>
  <namespaces>
    .....
    <add namespace="System.Web.Optimization" />
  </namespaces>
</pages>

I am adding bundles like so

bundles.Add(new StyleBundle("~/Styles").IncludeDirectory("~/Styles", "*.css"));
bundles.Add(new ScriptBundle("~/Scripts/App").IncludeDirectory("~/Scripts/App", "*.js"));

and rendering to my page like this

@Styles.Render("~/Styles")
@Scripts.Render("~/Scripts/App")

Which works great until I turn off debug

<compilation debug="false" targetFramework="4.0" />

The link and script tag added to my page are

<link href="/Styles?v=NMwU-eYeuzJZeywD3xbes6ngUXXJURhda30SEe9mb7Y1" rel="stylesheet">
<script src="/Scripts/App?v=NIL6McOTiWu9OPTVvgMfbmjFtYQhKZDQpRIbKK2kzSk1"></script>

Looking at Chromes network tab I get a 302 redirecting to

/Styles
/Scripts/App

Followed by a 404 :(

I can't seem to get this to work.... has anyone seen a similar issue?

1 Answer 1

1

Do you maybe have a conflict with your routing code?

Rick Anderson has a blog post about the bundling / minification features, including a note that you must be careful to avoid routing conflicts. You haven't posted your routing section, but it's something to take a look at.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.