Reputation: 9193
I am working on a blazor server web application.
I have to display a table with a big number of rows and columns.
I want to optimize.
Is there a way to enable data compression on blazor's websockets ?
Is there a compression enabled by defaut in Developpment or Production environnement ?
Thanks
Upvotes: 0
Views: 634
Reputation: 376
Unsure if this is going to be best answer for this but figured I would post it anyway. As other's have commented it would be best to utilize virtualization or pagination along with other app optimizations, but your question made me curious.
After a quick google search turns out asp.net has response compression.
The code used (Placed both as the very first things in their respective methods):
In Setup/ConfigureServices:
services.AddResponseCompression(o =>
{
o.EnableForHttps = true;
o.Providers.Add<BrotliCompressionProvider>();
o.Providers.Add<GzipCompressionProvider>();
o.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "image/svg+xml" });
});
services.Configure<BrotliCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Optimal;
});
services.Configure<GzipCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Optimal;
});
In Setup/Configure:
app.UseResponseCompression();
Default Blazor server app:
Default: 2.2kB transferred.
With changes: 1.5kB transferred.
Loading my own Blazor server app and testing it:
Default: 5.4kB transferred
With changes: 3.7kB transferred
Overall these changes appear to compress what is being transferred a bit more and the compression could most likely be even further optimized, but these changes should not be a substitute for optimizing your code.
Upvotes: 1