-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Add Blazor SSR css stylesheet link append-version component #49678
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
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
I think this is very much needed. Blazor SSR needs many quality of life improvements like this one before being ready for production. |
Here's my implementation: {ProjectName}.csproj: <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.0-*" /> Program.cs: builder.Services.AddMvcCore().AddRazorViewEngine(); Link.razor @using Microsoft.AspNetCore.Mvc.ViewFeatures
@inject IFileVersionProvider FileVersionProvider
@code {
[Parameter] public bool AppendVersion { get; set; } = true; // Change if you don't want to append version by default.
[Parameter] public required string Href { get; set; } = "";
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> AdditionalAttributes { get; set; } = default!;
string href = "";
protected override void OnInitialized()
{
href = AppendVersion ? FileVersionProvider.AddFileVersionToPath("/", Href) : Href;
}
}
<link href="@href" @attributes="AdditionalAttributes" /> Usage: <Link Href="/css/app.css" rel="stylesheet" AppendVersion="true" /> |
Or a more reusable version: using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace {APP};
public abstract class AppendableVersion : ComponentBase
{
[Inject] public IFileVersionProvider FileVersionProvider { get; set; } = default!;
[Parameter] public bool AppendVersion { get; set; } = true;
[Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object> AdditionalAttributes { get; set; } = default!;
protected string Source { get; set; } = "";
protected string Result { get; private set; } = "";
protected override void OnInitialized()
{
base.OnInitialized();
Result = AppendVersion ? FileVersionProvider.AddFileVersionToPath("/", Source) : Source;
}
} Link.razor: @inherits AppendableVersion
@code {
#pragma warning disable BL0007 // Auto property
[Parameter] public required string Href { get { return base.Source; } set { base.Source = value; } }
#pragma warning restore BL0007
}
<link Href="@base.Result" @attributes="AdditionalAttributes" /> Script.razor: @inherits AppendableVersion
@code {
#pragma warning disable BL0007 // Auto property
[Parameter] public required string Src { get { return base.Source; } set { base.Source = value; } }
#pragma warning restore BL0007 // Auto property
}
<script src="@base.Result" @attributes="AdditionalAttributes" /> |
Thanks for contacting us. We're moving this issue to the |
In Blazor SSR mode the entire page is rendered first before sending anything to the client, so the link tag doesn't have to "loaded before blazor". I have used my implementation of the Link component in production for a while and it works well. What is this argument based on @ArgoZhang ? |
Yes, you are right. My viewpoint is incorrect. |
Closing as a dupe of #52824 |
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Since Blazor SSR doesn't have tag helpers, there should be some components to help the move from Razor pages.
Please add a component to replace the 'append-version' option in the link-tag helper.
Describe the solution you'd like
Add a component, that takes the href parameter, and appends a version to it automatically or based on a boolean flag.
Additional context
Here is a crude example I hacked together:
The text was updated successfully, but these errors were encountered: