ASP.Net - JavaScript / Text GZip File Compression

1

Good afternoon, I'm having a hard time configuring traffic compression using GZip . Here are the steps I've taken to make compression work:

  • I have already enabled the features of windows related to compressing files on the web;

  • I've added the following code to my Web.Config so that I can read the files correctly and perform the compression:

  • <httpCompression directory="%SystemDrive%\websites\_compressed" minFileSizeForComp="0">  
        <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
        <staticTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" enabled="true" />
            <add mimeType="application/javascript" enabled="true" />
            <add mimeType="*/*" enabled="false" />
        </staticTypes>
    </httpCompression>
  • I've already enabled "Compactação dinâmica" and "Compactação estática" on the IIS console;

  • I've tried to remove the minimum file size to perform the compression and see if it really would be the size of the files.

  • I have also tried:

  •     <urlCompression doStaticCompression="true" doDynamicCompression="true"/>

    Can anyone help me?

    Note: I have already visited several other community posts related to the subject, but no answer solved my problem.

    IIS Settings:

    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    
        IIS configuration sections.
    
        For schema documentation, see
        %windir%\system32\inetsrv\config\schema\IIS_schema.xml.
        
        Please make a backup of this file before making any changes to it.
    
    -->
    
    <configuration>
    
        <!--
    
            The <configSections> section controls the registration of sections.
            Section is the basic unit of deployment, locking, searching and
            containment for configuration settings.
            
            Every section belongs to one section group.
            A section group is a container of logically-related sections.
            
            Sections cannot be nested.
            Section groups may be nested.
            
            <section
                name=""  [Required, Collection Key] [XML name of the section]
                allowDefinition="Everywhere" [MachineOnly|MachineToApplication|AppHostOnly|Everywhere] [Level where it can be set]
                overrideModeDefault="Allow"  [Allow|Deny] [Default delegation mode]
                allowLocation="true"  [true|false] [Allowed in location tags]
            />
            
            The recommended way to unlock sections is by using a location tag:
            <location path="Default Web Site" overrideMode="Allow">
                <system.webServer>
                    <asp />
                </system.webServer>
            </location>
    
        -->
        <configSections>
            <sectionGroup name="system.applicationHost">
                <section name="applicationPools" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="configHistory" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="customMetadata" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="listenerAdapters" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="log" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="serviceAutoStartProviders" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="sites" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="webLimits" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
            </sectionGroup>
    
            <sectionGroup name="system.webServer">
                <section name="asp" overrideModeDefault="Deny" />
                <section name="caching" overrideModeDefault="Allow" />
                <section name="cgi" overrideModeDefault="Deny" />
                <section name="defaultDocument" overrideModeDefault="Allow" />
                <section name="directoryBrowse" overrideModeDefault="Allow" />
                <section name="fastCgi" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="globalModules" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                <section name="handlers" overrideModeDefault="Deny" />
                <section name="httpCompression" overrideModeDefault="Deny" />
                <section name="httpErrors" overrideModeDefault="Allow" />
                <section name="httpLogging" overrideModeDefault="Deny" />
                <section name="httpProtocol" overrideModeDefault="Allow" />
                <section name="httpRedirect" overrideModeDefault="Allow" />
                <section name="httpTracing" overrideModeDefault="Deny" />
                <section name="isapiFilters" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
                <section name="modules" allowDefinition="MachineToApplication" overrideModeDefault="Deny" />
                <section name="applicationInitialization" allowDefinition="MachineToApplication" overrideModeDefault="Allow" />
                <section name="odbcLogging" overrideModeDefault="Deny" />
                <sectionGroup name="security">
                    <section name="access" overrideModeDefault="Deny" />
                    <section name="applicationDependencies" overrideModeDefault="Deny" />
                    <sectionGroup name="authentication">
                        <section name="anonymousAuthentication" overrideModeDefault="Deny" />
                        <section name="basicAuthentication" overrideModeDefault="Deny" />
                        <section name="clientCertificateMappingAuthentication" overrideModeDefault="Deny" />
                        <section name="digestAuthentication" overrideModeDefault="Deny" />
                        <section name="iisClientCertificateMappingAuthentication" overrideModeDefault="Deny" />
                        <section name="windowsAuthentication" overrideModeDefault="Deny" />
                    </sectionGroup>
                    <section name="authorization" overrideModeDefault="Allow" />
                    <section name="ipSecurity" overrideModeDefault="Deny" />
                    <section name="dynamicIpSecurity" overrideModeDefault="Deny" />
                    <section name="isapiCgiRestriction" allowDefinition="AppHostOnly" overrideModeDefault="Deny" />
                    <section name="requestFiltering" overrideModeDefault="Allow" />
                </sectionGroup>
                <section name="serverRuntime" overrideModeDefault="Deny" />
                <section name="serverSideInclude" overrideModeDefault="Deny" />
                <section name="staticContent" overrideModeDefault="Allow" />
                <sectionGroup name="tracing">
                    <section name="traceFailedRequests" overrideModeDefault="Allow" />
                    <section name="traceProviderDefinitions" overrideModeDefault="Deny" />
                </sectionGroup>
                <section name="urlCompression" overrideModeDefault="Allow" />
                <section name="validation" overrideModeDefault="Allow" />
                <sectionGroup name="webdav">
                    <section name="globalSettings" overrideModeDefault="Deny" />
                    <section name="authoring" overrideModeDefault="Deny" />
                    <section name="authoringRules" overrideModeDefault="Deny" />
                </sectionGroup>
                <section name="webSocket" overrideModeDefault="Deny" />
            </sectionGroup>
            <sectionGroup name="system.ftpServer">
                <section name="log" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
                <section name="firewallSupport" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
                <section name="caching" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
                <section name="providerDefinitions" overrideModeDefault="Deny" />
                <sectionGroup name="security">
                    <section name="ipSecurity" overrideModeDefault="Deny" />
                    <section name="requestFiltering" overrideModeDefault="Deny" />
                    <section name="authorization" overrideModeDefault="Deny" />
                    <section name="authentication" overrideModeDefault="Deny" />
                </sectionGroup>
                <section name="serverRuntime" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
            </sectionGroup>
        </configSections>
    
        <configProtectedData>
            <providers>
                <add name="IISWASOnlyRsaProvider" type="" description="Uses RsaCryptoServiceProvider to encrypt and decrypt" keyContainerName="iisWasKey" cspProviderName="" useMachineContainer="true" useOAEP="false" />
                <add name="IISCngProvider" type="Microsoft.ApplicationHost.CngProtectedConfigurationProvider" description="Uses Win32 Crypto CNG to encrypt and decrypt" keyContainerName="iisCngConfigurationKey" useMachineContainer="true" />
                <add name="IISWASOnlyCngProvider" type="Microsoft.ApplicationHost.CngProtectedConfigurationProvider" description="(WAS Only) Uses Win32 Crypto CNG to encrypt and decrypt" keyContainerName="iisCngWasKey" useMachineContainer="true" />
                <add name="AesProvider" type="Microsoft.ApplicationHost.AesProtectedConfigurationProvider" description="Uses an AES session key to encrypt and decrypt" keyContainerName="iisConfigurationKey" cspProviderName="" useOAEP="false" useMachineContainer="true" sessionKey="AQIAAA5mAAAApAAAE1i9v5I5UGXhWB12Q+czeTUqMSFI0GVRdtzVBlPFS1s5WIuIvTSKLmC+L19pFgdM65vwTQxPEyUzk3tiut0MdunQSIzegA1MQFmdvIAL8TMh+V5xIaqINRHqErzfQikmci58TwabaAqNN6jD/VPGGow7DK0a6m7bhgycfteqXFjYNxaejCAmTCSaYTSSUX0h6r1drzV6YSTbLXvl4bw5L3a7o91pgq153QeXGixQ5u001Gj9atMW4ZErYo8DOPEyO5MpgImDP10aUa44PNJaMsFD11brH6RjC3KFB1SeFdOcboo6L25lT73VKC4b2MMMyMprLYA3+pYYi3doGFd7WQ==" />
                <add name="IISWASOnlyAesProvider" type="Microsoft.ApplicationHost.AesProtectedConfigurationProvider" description="Uses an AES session key to encrypt and decrypt" keyContainerName="iisWasKey" cspProviderName="" useOAEP="false" useMachineContainer="true" sessionKey="AQIAAA5mAAAApAAAsXT7v6ghQu+IjV71ic8/nMeJsyrVE+9Uum4L10feXT1+fVTf8Foj5eYQp0HExmhJHVD6q5hqso3HkxibEfvQRZsD18QXvHp4E5B6p6L4ZYJQqL8LS/k/crs2Eiz8oZASEmRM9rOSjRdcOaLxUR/mHx4DlpHVEp1sG0EepCahOKtMFaoXKWZoqYKMZIDsqtvVZLZf8Q17Co/GIHB/A1+0KX9Sz56TnD7m5OhVA2l3gUy1cQ33GdkHB90uMBnuWQFuxgxIg5f2JgRcJaYnLfMOyG1AAGewWzifLqjHuRj5OPgi9hhcZCk6qMCwUSZyAa8iEqyR1G72B/MNzkUErJGixQ==" />
            </providers>
        </configProtectedData>
    
        <system.applicationHost>
    
            <applicationPools>
                <add name="DefaultAppPool" />
                <applicationPoolDefaults managedRuntimeVersion="v4.0">
                    <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="false" />
                </applicationPoolDefaults>
            </applicationPools>
    
            <!--
    
              The <customMetadata> section is used internally by the Admin Base Objects
              (ABO) Compatibility component. Please do not modify its content.
    
            -->
            <customMetadata>
                <key path="LM/W3SVC/INFO">
                    <property id="4012" dataType="String" userType="1" attributes="Inherit" value="Formato do Arquivo de Log Comum do NCSA,Formato do Arquivo de Log do Microsoft IIS,Formato do Arquivo de Log Estendido do W3C,Log de ODBC" />
                    <property id="2120" dataType="MultiSZ" userType="1" attributes="None" value="400,0,,,0&#xA;" />
                </key>
            </customMetadata>
    
            <!--
    
              The <listenerAdapters> section defines the protocols with which the
              Windows Process Activation Service (WAS) binds.
    
            -->
            <listenerAdapters>
                <add name="http" />
            </listenerAdapters>
    
            <log>
                <centralBinaryLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
                <centralW3CLogFile enabled="true" directory="%SystemDrive%\inetpub\logs\LogFiles" />
            </log>
    
            <sites>
                <site name="Default Web Site" id="1">
                    <application path="/">
                        <virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
                    </application>
                    <bindings>
                        <binding protocol="http" bindingInformation="*:80:" />
                    </bindings>
                </site>
                <siteDefaults>
                    <logFile logFormat="W3C" directory="%SystemDrive%\inetpub\logs\LogFiles" />
                    <traceFailedRequestsLogging directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles" />
                </siteDefaults>
                <applicationDefaults applicationPool="DefaultAppPool" />
                <virtualDirectoryDefaults allowSubDirConfig="true" />
            </sites>
    
            <webLimits />
    
        </system.applicationHost>
    
        <system.webServer>
    
            <asp />
    
            <caching enabled="true" enableKernelCache="true">
            </caching>
    
            <cgi />
    
            <defaultDocument />
    
            <directoryBrowse />
    
            <fastCgi />
    
            <!--
    
              The <globalModules> section defines all native-code modules.
              To enable a module, specify it in the <modules> section.
    
            -->
            <globalModules>
                <add name="UriCacheModule" image="%windir%\System32\inetsrv\cachuri.dll" />
                <add name="FileCacheModule" image="%windir%\System32\inetsrv\cachfile.dll" />
                <add name="TokenCacheModule" image="%windir%\System32\inetsrv\cachtokn.dll" />
                <add name="HttpCacheModule" image="%windir%\System32\inetsrv\cachhttp.dll" />
                <add name="DynamicCompressionModule" image="%windir%\System32\inetsrv\compdyn.dll" />
                <add name="StaticCompressionModule" image="%windir%\System32\inetsrv\compstat.dll" />
                <add name="ProtocolSupportModule" image="%windir%\System32\inetsrv\protsup.dll" />
                <add name="AnonymousAuthenticationModule" image="%windir%\System32\inetsrv\authanon.dll" />
            </globalModules>
    
            <handlers accessPolicy="Read, Script">
                <add name="TRACEVerbHandler" path="*" verb="TRACE" modules="ProtocolSupportModule" requireAccess="None" />
                <add name="OPTIONSVerbHandler" path="*" verb="OPTIONS" modules="ProtocolSupportModule" requireAccess="None" />
            </handlers>
    
        <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
          <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" />
          <dynamicTypes>
            <add mimeType="text/*" enabled="true" />
            <add mimeType="message/*" 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/x-javascript" enabled="true" />
            <add mimeType="application/atom+xml" enabled="true" />
            <add mimeType="application/xaml+xml" enabled="true" />
            <add mimeType="*/*" enabled="false" />
          </staticTypes>
        </httpCompression>
    
            <httpErrors />
    
            <httpLogging />
    
            <httpProtocol>
                <customHeaders>
                    <clear />
                </customHeaders>
                <redirectHeaders>
                    <clear />
                </redirectHeaders>
            </httpProtocol>
    
            <httpRedirect />
    
            <httpTracing />
    
            <isapiFilters />
    
            <modules>
                <add name="HttpCacheModule" lockItem="true" />
                <add name="DynamicCompressionModule" lockItem="true" />
                <add name="StaticCompressionModule" lockItem="true" />
                <add name="ProtocolSupportModule" lockItem="true" />
                <add name="AnonymousAuthenticationModule" lockItem="true" />
            </modules>
    
            <odbcLogging />
    
            <security>
    
                <access sslFlags="None" />
    
                <applicationDependencies />
    
                <authentication>
    
                    <anonymousAuthentication enabled="true" userName="IUSR" />
    
                    <basicAuthentication />
    
                    <clientCertificateMappingAuthentication />
    
                    <digestAuthentication />
    
                    <iisClientCertificateMappingAuthentication />
    
                    <windowsAuthentication />
    
                </authentication>
    
                <authorization />
    
                <ipSecurity />
    
                <isapiCgiRestriction />
    
                <requestFiltering />
    
            </security>
    
            <serverRuntime />
    
            <serverSideInclude />
    
            <staticContent />
    
            <tracing>
    
                <traceFailedRequests />
    
                <traceProviderDefinitions />
    
            </tracing>
    
            <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    
            <validation />
    
        </system.webServer>
    
    </configuration>
        
    asked by anonymous 10.12.2018 / 18:48

    1 answer

    1

    I found the solution by changing the applicationHost.config belonging to the project that is under development.

    Original text

      

    ApplicationHost.config is the root file of the configuration system   when you are using IIS 7 and above. It includes definitions of all   sites, applications, virtual directories and application pools,   as well as global defaults for the web server settings (similar to   machine.config and the root web.config for .NET Framework settings).

    Translation (Portugues-PT)

      

    ApplicationHost.config is the root file of the configuration system when you are using IIS 7 and above. It includes definitions for all sites, applications, virtual directories, and application pools, as well as global standards for Web server settings (similar to machine.config and the root web.config for .NET Framework settings.)

    I had set the applicationHost.config that existed in the IIS folder and not the one in the project folder just because I did not know it. When starting the application by VS, it takes this file into account and it was commented on the compression part of the files. Just uncomment and everything worked!

    Configuration file path:

    ~\SEU_PROJETO\.vs\config\applicationhost.config
        
    11.12.2018 / 12:30