如何解决Blazor / ASP.NET文本压缩-Google速度测试不同意,为什么?
context.Services.AddResponseCompression(o =>
{
o.EnableForHttps = true;
});
// We use brotli by default : https://docs.microsoft.com/en-us/aspnet/core/performance/response-compression?view=aspnetcore-3.1
//services.Configure<GzipCompressionProviderOptions>(o => o.Level = System.IO.Compression.CompressionLevel.Optimal);
context.Services.Configure<brotliCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Fastest;
});
和
app.UseResponseCompression();
当我在浏览器中签入时,似乎压缩已激活:
现在,我测试网站的速度,第一个建议是添加文本压缩。 所以,我不明白为什么会有这样的消息:
有人对这个问题有任何想法吗?
解决方法
The ASP.NET Core docs概述,使用CompressionLevel.Fastest
将导致压缩完成最快,而不是网页加载最快。
要获得最高级别的压缩,您应该使用CompressionLevel.Optimal
。
我找到了问题,希望它可以对其他人有所帮助。必须在UseStaticFiles之前放置对UseResponseCompression的调用,这样它也将考虑所有静态(css,js)文件。
// Must be before UseStaticFiles to compress static
//files and UseMvc to compress MVC responses
app.UseResponseCompression();
app.UseStaticFiles();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。