简体   繁体   中英

Combining javascript and css files with Rejuicer in ASP.NET MVC

I'm trying to integrate Rejuice (github page is here ) to my asp.net mvc project to combine js files. I downloaded it via nuget. It successfully added references and configured web.config file.

In global asax Application_Start I configured it as below:

    OnRequest.ForJs("~/Combined.js")
        .Combine
        .FilesIn("~/Scripts/").Matching("*.js")
        .Configure();

    OnRequest.ForJs("~/Combined.css")
        .Combine
        .FilesIn("~/Style/").Matching("*.css")
        .Configure();

In master page:

<%= Rejuiced.JsFor("~/Combined.js") %>
<%= Rejuiced.CssFor("~/Combined.css")%>

Running project in release mode results in downloading all the js and css files seperately. Running the site under IIS didn't help either. Isn't it supposed to combine and download only 2 files, one for js and another for css? What can cause this problem

Make sure that debug="true" is removed from your your web.config file:

Change

<system.web>
  <compilation debug="true" targetFramework="4.0">

to

<system.web>
  <compilation debug="false" targetFramework="4.0">

It doesn't matter if you build your code in Debug or Release -- Rejuicer respects the web.config debug setting, as it should. If this is set to true, then Rejuicer will not minify and combine files. It does this so that you can debug your scripts using non-minified files when working locally.

When you push your code into Production, your web.config.release transform will run, and remove the debug="true" attribute from your web.config file, so that your files will always be minified in production scenarios.

I had a very similar issue that was resolved by telling Rejuicer not to do anything in debug mode. There is a different way, however, than in the accepted answer to accomplish that. There are web.config settings that control Rejuicer's behavior that are not documented (as far as I can see), but that I found by inspecting the code. Set PreventPassThroughOnDebug to "true":

<configSections>
    <section name="compactor" type="Rejuicer.Configuration.CompactorConfiguration, Rejuicer"/>
    <section name="rejuicer" type="Rejuicer.Configuration.RejuicerConfiguration, Rejuicer"/>
  </configSections>
  <compactor Cache="true" Compact="true" Combine="true"/>
  <rejuicer PreventPassThroughOnDebug="true"/> <!-- THIS IS THE KEY.  SET TO "true" -->

Well I couldn't manage to make it work correctly. So I switched to combres . It started to work immediatelly as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM