Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bundling & minification not applying css & js using Asp.net 4.0 C#

Tags:

c#

asp.net

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...

like image 478
Prasad Raja Avatar asked Jan 11 '23 09:01

Prasad Raja


1 Answers

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.

like image 121
th1rdey3 Avatar answered Jan 30 '23 19:01

th1rdey3