简体   繁体   中英

gzip css and js files in asp.net

I am trying to enable gzip to all css and js files in the project.

i already activate the static and dynamic compression from IIS, and added this code to "web.config" file:

<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="*/*" enabled="false"/>
</dynamicTypes>
<staticTypes>
  <add mimeType="text/*" enabled="true"/>
  <add mimeType="message/*" enabled="true"/>
  <add mimeType="application/javascript" enabled="true"/>
  <add mimeType="*/*" enabled="false"/>
</staticTypes>

but its not working yet, in the console - network, i noticed that aspx page has Encoded-content : gzib, but not the css and js files.

Thanks

Depending on the size of your css and js files you might have to explicitly set the minFileSizeForComp -attribute. By default that value is set to 2700 bytes

<httpCompression directory="%SystemDrive%\websites\_compressed" minFileSizeForComp="1024">
    <!-- same as before -->
</httpCompression>

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