Skip to content

Commit 11e8b78

Browse files
committed
HTML Page compression added on deploy
1 parent 16f0038 commit 11e8b78

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

Startup.cs

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using Microsoft.AspNetCore.Http;
1313
using Microsoft.Net.Http.Headers;
1414
using StartupProject_Asp.NetCore_PostGRE.Services.EmailService;
15+
using WebMarkupMin.AspNetCore3;
1516

1617
namespace StartupProject_Asp.NetCore_PostGRE
1718
{
@@ -78,11 +79,28 @@ public void ConfigureServices(IServiceCollection services)
7879
.AddEntityFrameworkStores<ApplicationDbContext>()
7980
.AddDefaultTokenProviders()
8081
.AddDefaultUI();
81-
82+
83+
services.Configure<SecurityStampValidatorOptions>(options =>
84+
{
85+
options.ValidationInterval = TimeSpan.FromSeconds(1); //Update Auth every second after role updated
86+
});
8287

8388
services.AddControllersWithViews();
8489
services.AddRazorPages();
85-
90+
services.AddWebMarkupMin(
91+
options =>
92+
{
93+
options.AllowMinificationInDevelopmentEnvironment = false;
94+
options.AllowCompressionInDevelopmentEnvironment = false;
95+
})
96+
.AddHtmlMinification(
97+
options =>
98+
{
99+
options.MinificationSettings.RemoveRedundantAttributes = true;
100+
options.MinificationSettings.RemoveHttpProtocolFromAttributes = true;
101+
options.MinificationSettings.RemoveHttpsProtocolFromAttributes = true;
102+
})
103+
.AddHttpCompression();
86104
services.AddHsts(options =>
87105
{
88106
options.Preload = true;
@@ -92,11 +110,11 @@ public void ConfigureServices(IServiceCollection services)
92110
//options.ExcludedHosts.Add("www.example.com");
93111
});
94112

95-
//services.AddHttpsRedirection(options =>
96-
//{
97-
// options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
98-
// options.HttpsPort = 5001;
99-
//});
113+
services.AddHttpsRedirection(options =>
114+
{
115+
options.RedirectStatusCode = StatusCodes.Status307TemporaryRedirect;
116+
options.HttpsPort = 5001;
117+
});
100118
}
101119

102120
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -124,21 +142,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) //IWebHo
124142
//OnlyIfCached = false,
125143
MaxAge = TimeSpan.FromDays(365) // 1 year
126144
}
127-
}
128-
/*
129-
new StaticFileOptions()
130-
{
131-
//Configure Caching of static files
132-
OnPrepareResponse = context =>
133-
{
134-
context.Context.Response.Headers.Add("Cache-Control", "max-age=31622400, public, no-transform");
135-
//context.Context.Response.Headers.Add("Cache-Control", "no-cache, no-store");
136-
//context.Context.Response.Headers.Add("Expires", "-1");
137-
}
138-
}
139-
*/
140-
);
141-
145+
});
146+
app.UseWebMarkupMin();
142147
app.UseRouting();
143148

144149
app.UseAuthentication();

StartupProject-Asp.NetCore-PostGRE.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<PackageReference Include="Microsoft.Web.LibraryManager.Build" Version="2.1.113" />
3131
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
3232
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
33+
<PackageReference Include="WebMarkupMin.AspNetCore3" Version="2.8.15" />
3334
</ItemGroup>
3435

3536
</Project>

0 commit comments

Comments
 (0)