Asp.net core 學習筆記 ( IIS, static file 效能優化 )

refer : 

https://weblog.west-wind.com/posts/2017/Apr/27/IIS-and-ASPNET-Core-Rewrite-Rules-for-AspNetCoreModule

https://docs.microsoft.com/en-us/aspnet/core/performance/response-compression?tabs=aspnetcore2x

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/static-files

https://andrewlock.net/html-minification-using-webmarkupmin-in-asp-net-core/

https://github.com/Taritsyn/WebMarkupMin

 

core host in IIS 會攔截所有的請求, 包括靜態文件

可是 IIS 處理靜態文件壓縮等等還是不錯的 

那我們可以在 webconfig 裡去設定一下 

<configuration>
  <system.webServer>
    <rewrite>
        <rules>
            <rule name="wwwroot-static">
                <match url="([\S]+[.](html|htm|svg|js|css|png|gif|jpg|jpeg|json|mp3|mp4|woff|woff2))" />
                <action type="Rewrite" url="wwwroot/{R:1}" />
            </rule>
        </rules>
    </rewrite>
    <handlers>          
        <add name="StaticFileModuleSvg" path="*.svg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleJs" path="*.js" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleCss" path="*.css" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleJpeg" path="*.jpeg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleJpg" path="*.jpg" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModulePng" path="*.png" verb ="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="StaticFileModuleGif" path="*.gif" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
  <add name="StaticFileModuleJson" path="*.json" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
  <add name="StaticFileModuleMp4" path="*.mp4" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
  <add name="StaticFileModuleMp3" path="*.mp3" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
  <add name="StaticFileModuleWoff" path="*.woff" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
 <add name="StaticFileModuleWoff2" path="*.woff2" verb="*" modules="StaticFileModule" resourceType="File" requireAccess="Read" />
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />           
    </handlers>
    <aspNetCore processPath=".\Project.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <remove fileExtension=".json" />
      <mimeMap fileExtension=".json" mimeType="application/json" />
      <remove fileExtension=".mp4" />
      <mimeMap fileExtension=".mp4" mimeType="audio/mp4" />
      <remove fileExtension=".ogg" />
      <mimeMap fileExtension=".ogg" mimeType="audio/ogg" />
      <!--local iis no allow below-->
      <remove fileExtension=".less"/>
      <mimeMap fileExtension=".less" mimeType="text/css" />
      <remove fileExtension=".woff2"/>
      <mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
      <clientCache cacheControlMode="UseExpires" httpExpires="Tue, 12 Jan 2027 03:14:07 GMT" />
    </staticContent>
    <defaultDocument>
      <files>
        <clear />
        <add value="index.aspx" />
        <add value="Default.aspx" />
        <add value="index.html" />
        <add value="Default.html" />
      </files>
    </defaultDocument>
  </system.webServer>
</configuration>

做一個 rewrite 還有 handlers 就可以了. 

如果要處理 html minify 可以使用這個 plugin WebMarkupMin

 

關鍵詞:add file name modules path verb resourcetype staticfilemodule fileextension read

相關推薦:

ZABBIX 3.4 監控Nginx 狀態(七)

maven runnable jar

評論列表顯示及排序,個人中心顯示

VS2015 applicationhost.config 本地域名訪問

Python爬蟲入門教程:部落格園首頁推薦部落格排行的祕密

Hbuilder護眼主題分享

黃聰:JQUERY的datatables外掛,Date range filter時間段篩選功能

[從零開始搭網站五]http網站Tomcat配置web.xml和server.xml