Repository: dotnet/aspnetcore
File: src/Components/Endpoints/src/Builder/ResourcePreloadCollection.cs (C#)

Code before:
                    {
                        header.Append("; fetchpriority=").Append(property.Value);
                    }
                    else if (property.Name.Equals("preloadcrossorigin", StringComparison.OrdinalIgnoreCase))
                    {
                        header.Append("; crossorigin=").Append(property.Value);
                    }
                    else if (property.Name.Equals("integrity", StringComparison.OrdinalIgnoreCase))
                    {
                        header.Append("; integrity=\"").Append(property.Value).Append('"');
                    }
                    else if (property.Name.Equals("preloadorder", StringComparison.OrdinalIgnoreCase))
                    {
                        order = property.Value;
                    }
                }

                if (header != null)
                {
                    headers.Add((group, order, header.ToString()));
                }
            }

            foreach (var group in headers.GroupBy(h => h.Group))
            {
                _storage[group.Key ?? string.Empty] = group.OrderBy(h => h.Order).Select(h => h.Value).ToArray();
            }
        }
    }

    public bool TryGetLinkHeaders(string group, out StringValues linkHeaders)
        => _storage.TryGetValue(group, out linkHeaders);
}


Review comment (suggestion):
Sorting by the 'preloadorder' value as a string may lead to unexpected order when numeric values have multiple digits. Consider parsing the order values as integers to ensure a correct numerical sort.
```suggestion
                _storage[group.Key ?? string.Empty] = group.OrderBy(h => ParseOrder(h.Order)).Select(h => h.Value).ToArray();
```

Code after:
        headerBuilder.Append('<');
        headerBuilder.Append(url);
        headerBuilder.Append('>');

        int order = 0;
        foreach (var property in properties)
        {
            if (property.Name.Equals("preloadrel", StringComparison.OrdinalIgnoreCase))
            {
                headerBuilder.Append("; rel=").Append(property.Value);
            }
            else if (property.Name.Equals("preloadas", StringComparison.OrdinalIgnoreCase))
            {
                headerBuilder.Append("; as=").Append(property.Value);
            }
            else if (property.Name.Equals("preloadpriority", StringComparison.OrdinalIgnoreCase))
            {
                headerBuilder.Append("; fetchpriority=").Append(property.Value);
            }
            else if (property.Name.Equals("preloadcrossorigin", StringComparison.OrdinalIgnoreCase))
            {
                headerBuilder.Append("; crossorigin=").Append(property.Value);
            }
            else if (property.Name.Equals("integrity", StringComparison.OrdinalIgnoreCase))
            {
                headerBuilder.Append("; integrity=\"").Append(property.Value).Append('"');
            }
            else if (property.Name.Equals("preloadorder", StringComparison.OrdinalIgnoreCase))
            {
                if (!int.TryParse(property.Value, out order))
                {
                    order = 0;
                }
            }
        }

        return (order, headerBuilder.ToString());
    }

    public bool TryGetLinkHeaders(string group, out StringValues linkHeaders)
        => _storage.TryGetValue(group, out linkHeaders);
}