4

My Bundle Config is like this :

public class BaseBundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/Models").IncludeDirectory("~/Scripts/models/", "*.js", true));

        bundles.Add(new ScriptBundle("~/bundles/framework").Include(
                                            "~/Scripts/framework/frameworkmodels.js",
                                            "~/Scripts/framework/appbase.js",
                                            "~/Scripts/framework/directives/directives.js",
                                            "~/Scripts/framework/services/Services.js",
                                            "~/Scripts/framework/controllers/controllers.js",
                                            "~/Scripts/framework/filter/filters.js",
                                            "~/Scripts/app/filter/customFilters.js"
                                            ).Include("~/Scripts/app.js"));


        bundles.Add(new StyleBundle("~/Content/css").Include(
                                        "~/Content/libs/bootstrap/bootstrap.min.css",
                                        "~/Content/libs/bootstrap/bootstrap-theme.min.css",                                     
                                        "~/Content/libs/bootstrap/angular-csp.css",
                                        "~/Content/libs/bootstrap/mainStyle.css"
                                        ));

        BundleTable.EnableOptimizations = true;

    }
}

and I used bundle's inside index.cshtml like this:

......
@System.Web.Optimization.Scripts.Render("~/bundles/framework")

.....
@System.Web.Optimization.Styles.Render("~/Content/css")

after publish on IIS 8.5. bundling and minification works as expected but bundles are not compressed for both ScriptBundle and StyleBundle. response content-type always is text/javascript or text/css. why gzip compression is not working?

chrome network tab screenshot

dynamic and static content compression both are set to true in web.config

<system.webServer>

    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
</system.webServer>

MVC assembly's version: System.Web.Mvc 5.2.3.0 System.Web.Optimization 1.1.0 and Dynamic Compression module is also installed on server.

new info: two screenshot, first is IIS request tracing log that show dynamic compression module doing it's job, and second one is chrome network tab response headers for that request. why Transfer-Encoding:chunked and response is not gzip :\

IIS Trace Log

chrome network tab

thanks for your ideas

hvojdani
  • 460
  • 3
  • 13
  • 1
    for IIS 7.5 but may help - http://stackoverflow.com/questions/6938713/gzip-compression-on-iis-7-5-is-not-working – James P Feb 18 '17 at 23:09

2 Answers2

2

Add an <httpCompression> section to your web.config before or after <urlCompression>. Here is mine:

<httpCompression directory="%SystemDrive%\websites\_compressed" minFileSizeForComp="1024">
    <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
    <dynamicTypes>               
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </dynamicTypes>
    <staticTypes>
        <add mimeType="text/*" enabled="true" />
        <add mimeType="message/*" enabled="true" />
        <add mimeType="application/javascript" enabled="true" />
        <add mimeType="application/x-javascript" enabled="true" />
        <add mimeType="application/json" enabled="true" />
        <add mimeType="*/*" enabled="false" />
    </staticTypes>
</httpCompression>

Note this doesn't kick in unless the bundle is 1024 bytes or larger (minFileSizeForComp) so you don't waste time compressing files that are already very small.

Note also that you'll need to make sure the gzip.dll is in this folder.

Joe Wilson
  • 5,591
  • 2
  • 27
  • 38
  • just added config but no success – hvojdani Feb 19 '17 at 06:55
  • 1
    Sorry that didn't work. Did you already go through all the troubleshooting in the link James provided? There are a lot of factors that can add up to gzip not working as you might exepct. http://stackoverflow.com/questions/6938713/gzip-compression-on-iis-7-5-is-not-working – Joe Wilson Feb 20 '17 at 03:00
2

I found the problem point, hardware firewall between clients and IIS decompress gzip data and after processing content, send it chunked to client, when i try from other clients outside of company, gzip compression work as I expected.

hvojdani
  • 460
  • 3
  • 13
  • 1
    After 3 hours of fiddling with the server this solved the problem. Is there anyway this can be overcome? – PotatoJam Jun 01 '17 at 13:10