在編寫前端代碼的過程中經常會遇到使用特定的字體(*.woff,*.svg),此時在加載字體時請求會被返回
Failed to load resource: the server responded with a status of 404 (Not Found)。
原因是,默認在IIS上是沒有添加對*.woff,*.svg文件的Mime類型,因此在客戶端請求此類文件時得到的都是404。
所以我們只需要在我們對應網站下的Mime類型中添加文件對應的類型就行了
- .woff application/x-font-woff
- .woff2 application/x-font-woff
- .svg image/svg+xml
另外在mvc中,設置了上述Mime類型后get請求字體時任然會出現404的問題,這個時候需要在我們的web工程中的config的system.webServer節點中添加如下的代碼來支持
<staticContent> <remove fileExtension=".woff"/> <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" /> <remove fileExtension=".woff2"/> <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" /> <remove fileExtension=".ttf" /> <mimeMap fileExtension=".ttf" mimeType="application/x-font-truetype" /> <remove fileExtension=".svg" /> <mimeMap fileExtension=".svg" mimeType="image/svg+xml" /> <remove fileExtension=".otf" /> <mimeMap fileExtension=".otf" mimeType="application/x-font-opentype" /> <remove fileExtension=".eot" /> <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" /> </staticContent>
具體類型對照可以參照 w3cschoolMIME類型