Taritsyn / BundleTransformer

Bundle Transformer - a modular extension for System.Web.Optimization (also known as the Microsoft ASP.NET Web Optimization Framework).
Apache License 2.0
130 stars 19 forks source link

There's a way to compress bundle results via dynamic compress or filters? #29

Closed ericfelipe99 closed 5 years ago

ericfelipe99 commented 5 years ago

I set up dynamic compress on web.config, with all javascript mime-types but it's not compressed anyway. there's a solution for zgip compress the bundle ? Or use the automatic iis dynamic compress for that?

thanks.

Taritsyn commented 5 years ago

there's a solution for zgip compress the bundle ?

No. Use a GZip-compression at IIS level.

I set up dynamic compress on web.config, with all javascript mime-types but it's not compressed anyway.

Do static compression work correctly?

ericfelipe99 commented 5 years ago

there's a solution for zgip compress the bundle ?

No. Use a GZip-compression at IIS level.

I set up dynamic compress on web.config, with all javascript mime-types but it's not compressed anyway.

Do static compression work correctly?

thanks for your reply.

At IIS level not working to me. I enabled dynamic and static compression, but none of them worked.

<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
        <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>
Taritsyn commented 5 years ago

I enabled dynamic and static compression, but none of them worked.

Are other types of content compressed by GZip (e.g. text/css or text/xml)?

ericfelipe99 commented 5 years ago

I enabled dynamic and static compression, but none of them worked.

Are other types of content compressed by GZip (e.g. text/css or text/xml)?

yes. i use a site to test: https://developers.google.com/speed/pagespeed/insights/ I working at otimize site (segurofacil.com.br).

all html and css are compressed. I use bundle transformer for compile scss and minify css.... but with css works fine.

maybe something is blocking this compression? or the mime type or extension was not recognized by iis as script?

Taritsyn commented 5 years ago

Сontent of the scriptsbase bundle was not processed by the Bundle Transformer, because there are no regions:

//#region URL: ….js
…
//#endregion

The sfstyles bundle successfully passed such processing.

Taritsyn commented 5 years ago

In your Web.config file has the combineFilesBeforeMinification setting?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  …
  <bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
    <core …>
      …
      <js … combineFilesBeforeMinification="true">
        …
      </js>
      …
    </core>
    …
  </bundleTransformer>
  …
</configuration>
ericfelipe99 commented 5 years ago

In your Web.config file has the combineFilesBeforeMinification setting?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  …
  <bundleTransformer xmlns="http://tempuri.org/BundleTransformer.Configuration.xsd">
    <core …>
      …
      <js … combineFilesBeforeMinification="true">
        …
      </js>
      …
    </core>
    …
  </bundleTransformer>
  …
</configuration>

All my configurations are in bundleconfig.cs file.

BundleTable.EnableOptimizations = true;
BundleResolver.Current = new BundleTransformer.Core.Resolvers.CustomBundleResolver();

bundles.UseCdn = true;

var yuiCss = new BundleTransformer.Yui.Minifiers.YuiCssMinifier();

var ajaxMinifierJS = new BundleTransformer.MicrosoftAjax.Minifiers.MicrosoftAjaxJsMinifier();
ajaxMinifierJS.PreserveImportantComments = true;
ajaxMinifierJS.StripDebugStatements = true;

var nullBuilder = new NullBuilder();
var nullOrderer = new NullOrderer();

var cssUrlTransform = new BundleTransformer.Core.PostProcessors.UrlRewritingCssPostProcessor();
var postTransforms = new List<BundleTransformer.Core.PostProcessors.IPostProcessor>();
postTransforms.Add(cssUrlTransform);

/*styles*/
var styleTransformer = new StyleTransformer(yuiCss, postTransforms);
styleTransformer.CombineFilesBeforeMinification = false; 

/*script*/
ScriptTransformer scriptTransformer = new ScriptTransformer(ajaxMinifierJS);
scriptTransformer.EnableTracing = false; // remove o nome dos arquivos do arquivo final compilado
scriptTransformer.CombineFilesBeforeMinification = true; 
... 

// scripts base, jquery, boostrap, 
var scriptsBase = new ScriptBundle("~/scripts/scriptsbase");
scriptsBase.Include("........ ");
scriptsBase.Builder = nullBuilder;
scriptsBase.Transforms.Add(scriptTransformer);
scriptsBase.Orderer = nullOrderer;
bundles.Add(scriptsBase);
Taritsyn commented 5 years ago

Replace this line:

var scriptsBase = new ScriptBundle("~/scripts/scriptsbase");

With the following line:

var scriptsBase = new Bundle("~/scripts/scriptsbase");

The StyleBundle is also replace by Bundle.

ericfelipe99 commented 5 years ago

Replace this line:

var scriptsBase = new ScriptBundle("~/scripts/scriptsbase");

With the following line:

var scriptsBase = new Bundle("~/scripts/scriptsbase");

The StyleBundle is also replace by Bundle.

Hi, tanks for reply. I changed but it not worked... maybe this is a problem of IIS 7.5 or something else... It's compress css like a charm... i think its a problem with something else...

Taritsyn commented 5 years ago

I changed but it not worked...

In any case, this fix will speed up performance.

maybe this is a problem of IIS 7.5 or something else...

If static JS files are not compressed, then it is most likely a problem at IIS level.