Skip to content

Commit

Permalink
WN (#33035)
Browse files Browse the repository at this point in the history
* WN

* WN

* WN

* WN

* Apply suggestions from code review

Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>

---------

Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>
  • Loading branch information
Rick-Anderson and tdykstra committed Jul 11, 2024
1 parent ccf9d05 commit 575ebb5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
4 changes: 1 addition & 3 deletions aspnetcore/release-notes/aspnetcore-9.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ author: rick-anderson
description: Learn about the new features in ASP.NET Core 9.0.
ms.author: riande
ms.custom: mvc
ms.date: 6/10/2024
ms.date: 6/9/2024
uid: aspnetcore-9
---
# What's new in ASP.NET Core 9.0
Expand Down Expand Up @@ -64,5 +64,3 @@ The following sections describe miscellaneous new features.
[!INCLUDE[](~/release-notes/aspnetcore-9/includes/web_asset_delivery.md)]

[!INCLUDE[](~/release-notes/aspnetcore-9/includes/asp0026.md)]

[!INCLUDE[](~/release-notes/aspnetcore-9/includes/optimize-file-delivery.md)]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
### Optimizing static web asset delivery

Creating performant web apps includes optimizing asset delivery to the browser. This involves many aspects such as:
Following production best practices for serving static assets requires a significant amount of work and technical expertise. Without optimizations like compression, caching, and [fingerprints](https://en.wikipedia.org/wiki/Fingerprint_(computing)):

* Setting the [ETag](https://developer.mozilla.org/docs/Web/HTTP/Headers/ETag) and [Last-Modified](https://developer.mozilla.org/docs/Web/HTTP/Headers/Last-Modified) headers.
* Setting up proper [caching headers](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control).
* Using [caching middleware](xref:performance/caching/middleware).
* Serving [compressed](/aspnet/core/performance/response-compression) versions of the assets when possible.
* Using a [CDN](/microsoft-365/enterprise/content-delivery-networks?view=o365-worldwide&preserve-view=true) to serve the assets closer to the user.
* Minifying the assets.
* The browser has to make additional requests on every page load.
* More bytes than necessary are transferred through the network.
* Sometimes stale versions of files are served to clients.

Creating performant web apps requires optimizing asset delivery to the browser. Possible optimizations include:

* Serve a given asset once until the file changes or the browser clears its cache. Set the [ETag](https://developer.mozilla.org/docs/Web/HTTP/Headers/ETag) header.
* Prevent the browser from using old or stale assets after an app is updated. Set the [Last-Modified](https://developer.mozilla.org/docs/Web/HTTP/Headers/Last-Modified) header.
* Set up proper [caching headers](https://developer.mozilla.org/docs/Web/HTTP/Headers/Cache-Control).
* Use [caching middleware](xref:performance/caching/middleware).
* Serve [compressed](/aspnet/core/performance/response-compression) versions of the assets when possible.
* Use a [CDN](/microsoft-365/enterprise/content-delivery-networks?view=o365-worldwide&preserve-view=true) to serve the assets closer to the user.
* Minimize the size of assets served to the browser. This optimization doesn't include minification.

[`MapStaticAssets`](https://source.dot.net/#Microsoft.AspNetCore.StaticAssets/StaticAssetsEndpointRouteBuilderExtensions.cs,18) is a new middleware that helps optimize the delivery of static assets in an app. It's designed to work with all UI frameworks, including Blazor, Razor Pages, and MVC. It's typically a drop-in replacement for [UseStaticFiles](/dotnet/api/microsoft.aspnetcore.builder.staticfileextensions.usestaticfiles):

Expand Down Expand Up @@ -77,6 +84,11 @@ MudBlazor.min.js | 47.4 | 9.2 | 80.59%

Optimization happens automatically when using `MapStaticAssets`. When a library is added or updated, for example with new JavaScript or CSS, the assets are optimized as part of the build. Optimization is especially beneficial to mobile environments that can have a lower bandwidth or an unreliable connections.

For more information on the new file delivery features, see the following resources:

* <xref:fundamentals/static-files?view=aspnetcore-9.0>
* <xref:blazor/fundamentals/static-files?view=aspnetcore-9.0>

### Enabling dynamic compression on the server vs using `MapStaticAssets`

`MapStaticAssets` has the following advantages over dynamic compression on the server:
Expand Down

0 comments on commit 575ebb5

Please sign in to comment.