OTS parsing error: Size of decompressed WOFF 2.0 is less than compressed size

OTS parsing error: Size of decompressed WOFF 2.0 is less than compressed size

Raymond Tang Raymond Tang 0 3 0.01 index 6/29/2024

Most recently, I encountered an strange error in my web application where web fonts are used:

Failed to decode downloaded font: https://localhost:50001/css/material-icons-outlined.woff2 OTS parsing error: Size of decompressed WOFF 2.0 is less than compressed size

In stylesheet file, Google Material Icons font is defined with the following code:

@font-face {
    font-family: "Material Icons Outlined";
    font-style: normal;
    font-weight: 400;
    src: local('Material Icons Outlined'), url(material-icons-outlined.woff2) format("woff2"), url(material-icons-outlined.woff) format("woff");
    font-display: swap;
}

The fonts are served in ASP.NET Core application via UseStaticFiles extension:

  app.UseStaticFiles(new StaticFileOptions()
            {
                HttpsCompression = Microsoft.AspNetCore.Http.Features.HttpsCompressionMode.Compress,
                OnPrepareResponse = (context) =>
                {
                    var headers = context.Context.Response.GetTypedHeaders();
                    headers.CacheControl = new Microsoft.Net.Http.Headers.CacheControlHeaderValue
                    {
                        Public = true,
                        MaxAge = TimeSpan.FromDays(365)
                    };
                }
            });

As configured, compression is used. This has been working fine until I am updating the frontend packages for Kontext. I'm not sure whether it is related to my ASP.NET Core update or the browser update.

Resolution

After searching around. I find out one resolution by defining using only one font file:

@font-face {
    font-family: "Material Icons Outlined";
    font-style: normal;
    font-weight: 400;
    src: local('Material Icons Outlined'), url(material-icons-outlined.woff2) format("woff2");
    font-display: swap;
}

The above font face definition removed woff one and only kept woff2 and it worked.

I'm not familiar with the underlying details for fonts, especially woff and woff2. If you have any other approaches to fix this issue, please comment.

asp.net-core

Join the Discussion

View or add your thoughts below

Comments