Closed hakonamatata closed 6 years ago
In your startup.cs you can write
app.UseStaticFiles(new StaticFileOptions()
{
OnPrepareResponse = context =>
{
//Do not add cache to json files. We need to have new versions when we add new translations.
if(!context.Context.Request.Path.Value.Contains(".json")) {
context.Context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromDays(30) //Cache everything except json for 30 days
};
} else {
context.Context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromMinutes(15) //Cache json for 15 minutes
};
}
}
});
This will add 30 days cache to all files except .json files.
So the problem with Uglify is that it'd complicate the build process a bit, in that - if you truly want to "Uglify", you can't have a Vendor file. So we'd have different ones for Dev & Prod.
All of that leg work and complicated webpack builds has been setup in the CLI, so when we move to that - we'll immediately get to reap all the benefits :)
Glad it's working so far for everyone though ! :+1: Pumped.
Thanks @Flood, that worked perfectly!
Added this to Startup.cs:
// app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions()
{
OnPrepareResponse = c =>
{
//Do not add cache to json files. We need to have new versions when we add new translations.
if (!c.Context.Request.Path.Value.Contains(".json"))
{
c.Context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromDays(30) // Cache everything except json for 30 days
};
}
else
{
c.Context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue()
{
MaxAge = TimeSpan.FromMinutes(15) // Cache json for 15 minutes
};
}
}
});
Perfect score on phone and close to perfect on desktop! Very impressive.
I suggest we add Floods code to the repo, I could make a pull request, but don't want to take credit for @Flood's code π
I understand @MarkPieszak π
Haha, no worries! Go ahead! π
I think it's a good idea, let's add it in there! Send a PR whenever πΎ
done and done. I'm closing this issue since everything is resolved now.
Hi
Great work on version 5.0 @MarkPieszak :heart:
Want to show a really nice image I got after uploading the new version to Azure. (Did comment out the translate part)
That is very close to a perfect score from Google Pagespeed insight!
The only thing missing is Minifying the .js files, it would be nice to add this to the build process.
This is already in the webpack.config.js so I guess this is meant to be added at some point
Second part, this might be just a Azure thing, but I haven't been able to set the expiration date of the files.
I tried adding this to web.config:
But I still get
Does anyone know a solution for this?