ASP.Net - Javascript file compression / Text Gzip

Asked

Viewed 76 times

1

Good afternoon, I’m having a hard time configuring traffic compression using the GZip. Below are the steps I have already taken to effect compression:

  1. I’ve already enabled windows features related to web file compression;

  2. I added the following code to my Web.Config so that you can read the files correctly and perform 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>

  1. I’ve already activated the "Compactação dinâmica" and "Compactação estática" on the console of IIS;

  2. I have tried to remove the minimum file size to perform the compression and see if it really would be the file size.

  3. I’ve tried too:

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

I wonder if someone could help me?

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

Settings IIS:

<?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>

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 websites, 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 (English to English)

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

I had configured the applicationHost.config that existed in the IIS and not the one in the folder of the project just by not knowing it. When starting the application by VS, it takes this file into consideration and in it was commented the compression part of the files. All it took was the bleaching and it all worked out!

Path to configuration file:

~\SEU_PROJETO\.vs\config\applicationhost.config

Browser other questions tagged

You are not signed in. Login or sign up in order to post.