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

后端 未结 5 501
独厮守ぢ
独厮守ぢ 2021-01-13 15:55

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

相关标签:
5条回答
  • 2021-01-13 16:10

    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.

    0 讨论(0)
  • 2021-01-13 16:20

    in your web config file set this:

    <compilation debug="false" targetFramework="4.0">
    
    0 讨论(0)
  • 2021-01-13 16:21

    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.

    0 讨论(0)
  • 2021-01-13 16:28

    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

    0 讨论(0)
  • 2021-01-13 16:34

    Try this in your web.config

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

    see MSDN

    0 讨论(0)
提交回复
热议问题