4

I am new to this concept, this is my first project implementing the optimization concept with (Bundling & minification)

Just i am trying to test with simple js & css

Test.aspx

<html>
<%@ import namespace="System.Web.Optimization" %>
<html>
<head runat="server">
    <%: Scripts.Render("~/bundles/js") %>
    <%: Styles.Render("~/bundles/css") %>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <button id="tests">
            testing</button>
    </div>
    </form>
</body>
</html>

Global.Asax look like this

protected void Application_Start(object sender, EventArgs e)
{
    RegisterBundles(BundleTable.Bundles);
}

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/js").Include(
     "~/script/jquery-1.8.2.min.js",
     "~/script/s.js"));

    bundles.Add(new StyleBundle("~/bundles/css").Include(
     "~/css/master.css"));

    BundleTable.EnableOptimizations = true;
}


Project Structure Look like this

enter image description here


browser View enter image description here

the file are Bundling, but in Css i have some style to render in the webpage, it nothing appearing on this,

Sample like jquery files also

for more info abt this post, please check this..Click here

can you guide me to achieve this...

Nico
  • 12,493
  • 5
  • 42
  • 62
Prasad Raja
  • 685
  • 1
  • 9
  • 37
  • Can you show us your aspx code. After examining the screenshot better it appears as if you are actually bundling some of your resources but across multiple bundles.. – Nico Jan 23 '14 at 04:56
  • i can't apply the .aspx code here... here it was not accepting the html tags here...for aspx page check this link http://forums.asp.net/t/1963043.aspx?Bundling+minification+not+applying+css+js+using+Asp+net+4+0+C+ – Prasad Raja Jan 23 '14 at 05:09
  • I added your code. Can you send a sample of what any of the bundled files are from the items in the screen shot that start with `js?v=` – Nico Jan 23 '14 at 05:19
  • Thanks you...issue is resolved now.... – Prasad Raja Jan 23 '14 at 05:59
  • I downloaded your version and found the problem. See post – Nico Jan 23 '14 at 06:08
  • i also followed your step pnly.. after removing that (bundles folder under js & css) it working fine, i though manually we need to know.... then i come know that, it will create automatically @ runtime ... anyway thanks for your support.. – Prasad Raja Jan 23 '14 at 06:51
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/45873/discussion-between-prasad-raja-and-nico) – Prasad Raja Jan 23 '14 at 07:10

5 Answers5

5

Your bundling is working, problem is you css are not working when bundled.

Change your style sheet bundle name to this:

bundles.Add(new StyleBundle("~/css/allcss").Include("~/css/master.css"));

This should solve your problem.

P.S. if you keep your css files in multiple folders, then create a bundle for each folder. You can use the IncludeFolder method to make your job easier.

th1rdey3
  • 4,176
  • 7
  • 30
  • 66
2

Set this in web config:

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

Why is my CSS bundling not working with a bin deployed MVC4 app?

Bundled scripts not working MVC

Community
  • 1
  • 1
2

Prasad Raja,

When debugging or when your web.config has the setting

<compilation debug="true" ..>

the script bundling and minification is disabled. Also if you set EnableOptimizations = false will also disable budling and minification regardless of the debug=true setting.

Try changing your web.config and try again.

OK so after I reviewed the code and dug deeper into the problem the reason why this is happening is the paths ~/bundles/js and ~/bundles/css exist. Therefore your IIS (Express) is trying to load the contents of the directory. To get this to work ensure you set your compilation debug = false (it was set to true on the project download). Such as

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

Next locate the ~/bundle folder and DELETE IT... Finally rebuild your application and run the project. However dont run it in debug or it will try and set your debug flag above back to true.

This is working on my machine now for both JS and CSS.

Nico
  • 12,493
  • 5
  • 42
  • 62
0

Try this in your web.config

<configuration>
    ...
    <system.web>
        <compilation
            debug="true"
            ...
        >
        ...
        </compilation>
    </system.web>
</configuration>

see MSDN

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
  • can you check this link , http://forums.asp.net/t/1963043.aspx?Bundling+minification+not+applying+css+js+using+Asp+net+4+0+C+ .... i have given detail info about the problem – Prasad Raja Jan 23 '14 at 04:57
0

in your web config file set this:

<compilation debug="false" targetFramework="4.0">
user3164883
  • 91
  • 3
  • 8