Skip to content

[Blazor] Use <LinkPreload /> component to preload assets #62225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jun 13, 2025

Conversation

maraf
Copy link
Member

@maraf maraf commented Jun 3, 2025

Using link headers has several disadvantages

  • It's complicated to correct identify root without doing per request processing
  • It's more indirect when people want to turn the feature off

For these reasons we have decided to switch to a component-based approach. Thanks to <base href="..."> element, preload links are correctly rooted.
This PR adds <LinkPreload /> component that in case of InteractiveWebAssembly component presence on the page generates preloading links into the place where the component is used, into the HTML head, after the <base href="...">. In case there isn't any InteractiveWebAssembly, the component does nothing.

This PR also updates the BlazorWeb template to include the <LinkPreload /> component.

Fixes #62174

@maraf maraf added this to the 10.0-preview6 milestone Jun 3, 2025
@maraf maraf self-assigned this Jun 3, 2025
@maraf maraf added the area-blazor Includes: Blazor, Razor Components label Jun 3, 2025
@maraf maraf changed the title [Blazor] Root preload URLs [Blazor] Compute relative root in preloading paths Jun 5, 2025
@maraf maraf changed the title [Blazor] Compute relative root in preloading paths [Blazor] Use <LinkPreload /> component to preload assets Jun 12, 2025
Copy link
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@maraf maraf marked this pull request as ready for review June 13, 2025 09:47
@maraf maraf requested a review from a team as a code owner June 13, 2025 09:47
@maraf maraf enabled auto-merge (squash) June 13, 2025 11:46
@maraf maraf merged commit fe7fe16 into dotnet:main Jun 13, 2025
27 checks passed
@maraf maraf deleted the BlazorPreloadRoot branch June 13, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[blazor][wasm] preload links are not properly rooted for app start from deep link
2 participants