Repository: dotnet/aspnetcore
File: src/Components/Endpoints/src/Rendering/EndpointHtmlRenderer.Streaming.cs (C#)

Code before:
        {
            var serializedEndRecord = JsonSerializer.Serialize(endMarker, ServerComponentSerializationSettings.JsonSerializationOptions);
            output.Write("<!--Blazor:");
            output.Write(serializedEndRecord);
            output.Write("-->");
        }
    }

    private void AppendWebAssemblyPreloadHeaders()
    {
        var assets = _httpContext.GetEndpoint()?.Metadata.GetMetadata<ResourceAssetCollection>();
        if (assets != null)
        {
            var headers = new List<(string? Order, string Value)>();
            foreach (var asset in assets)
            {
                if (asset.Properties == null)
                {
                    continue;
                }

                // Use preloadgroup=webassembly to identify assets that should to be preloaded
                string? header = null;
                foreach (var property in asset.Properties)
                {
                    if (property.Name.Equals("preloadgroup", StringComparison.OrdinalIgnoreCase) && property.Value.Equals("webassembly", StringComparison.OrdinalIgnoreCase))
                    {
                        header = $"<{asset.Url}>";
                        break;
                    }
                }

                if (header == null)
                {
                    continue;
                }

                string? order = null;
                foreach (var property in asset.Properties)
                {
                    if (property.Name.Equals("preloadrel", StringComparison.OrdinalIgnoreCase))
                    {
                        header = String.Concat(header, "; rel=", property.Value);
                    }
                    else if (property.Name.Equals("preloadas", StringComparison.OrdinalIgnoreCase))
                    {
                        header = String.Concat(header, "; as=", property.Value);
                    }
                    else if (property.Name.Equals("preloadpriority", StringComparison.OrdinalIgnoreCase))
                    {
                        header = String.Concat(header, "; fetchpriority=", property.Value);

Review comment (suggestion):
The feature for identifying assets that should be preload seems quite generic. I have introduced here an ability to group such preloads. It would give us possibility in the future to define component or other API that would allow to preload other assets in other scenarios.

Alternatively, I can prefix all the SWA properties with `webassembly-` to make it WebAssembly specific and leave the whole feature WebAssembly specific.

I keen to leave the room for future extension with `preloadgroup`.

Code after:
            var serializedEndRecord = JsonSerializer.Serialize(endMarker, ServerComponentSerializationSettings.JsonSerializationOptions);
            output.Write("<!--Blazor:");
            output.Write(serializedEndRecord);
            output.Write("-->");
        }
    }

    private void AppendWebAssemblyPreloadHeaders()
    {
        var preloads = _httpContext.GetEndpoint()?.Metadata.GetMetadata<ResourcePreloadCollection>();
        if (preloads != null && preloads.TryGetLinkHeaders("webassembly", out var linkHeaders))
        {
            _httpContext.Response.Headers.Link = StringValues.Concat(_httpContext.Response.Headers.Link, linkHeaders);
        }
    }

    private static bool IsProgressivelyEnhancedNavigation(HttpRequest request)
    {
        // For enhanced nav, the Blazor JS code controls the "accept" header precisely, so we can be very specific about the format
        var accept = request.Headers.Accept;
        return accept.Count == 1 && string.Equals(accept[0]!, "text/html; blazor-enhanced-nav=on", StringComparison.Ordinal);
    }

    private readonly struct ComponentIdAndDepth
    {
        public int ComponentId { get; }

        public int Depth { get; }

        public ComponentIdAndDepth(int componentId, int depth)
        {
            ComponentId = componentId;
            Depth = depth;
        }
    }

    private readonly struct SequenceAndKey
    {
        public int Sequence { get; }

        public object? Key { get; }

        public SequenceAndKey(int sequence, object? key)
        {
            Sequence = sequence;
            Key = key;
        }
    }
}