Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ namespace Miniblog.Core
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;

using Miniblog.Core.Services;

using System.IO.Compression;
using System.Linq;

using WebEssentials.AspNetCore.OutputCaching;

using WebMarkupMin.AspNetCore2;
Expand Down Expand Up @@ -53,6 +57,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseExceptionHandler("/Shared/Error");
app.UseHsts();
}
app.UseResponseCompression();

app.Use(
(context, next) =>
Expand Down Expand Up @@ -86,6 +91,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
endpoints.MapControllerRoute("default", "{controller=Blog}/{action=Index}/{id?}");
});

}

/// <remarks>This method gets called by the runtime. Use this method to add services to the container.</remarks>
Expand Down Expand Up @@ -151,6 +157,25 @@ public void ConfigureServices(IServiceCollection services)
pipeline.CompileScssFiles()
.InlineImages(1);
});

// Compress HTTP response
services.AddResponseCompression(options =>
{
options.Providers.Add<BrotliCompressionProvider>();
options.Providers.Add<GzipCompressionProvider>();
options.EnableForHttps = true;
options.MimeTypes =
ResponseCompressionDefaults.MimeTypes.Concat(
new[] { "application/json" });
});
services.Configure<BrotliCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Fastest;
});
services.Configure<GzipCompressionProviderOptions>(options =>
{
options.Level = CompressionLevel.Fastest;
});
}
}
}