CdnScriptTagHelper Class
Definition
- Namespace
- Cuemon.AspNetCore.Razor.TagHelpers
- Assemblies
- Cuemon.AspNetCore.Razor.TagHelpers.dll
Provides an implementation targeting <script> elements that supports ICacheBusting versioning of a static script placed on a location with a CDN role. This class cannot be inherited.
[HtmlTargetElement("cdn-script")]
public sealed class CdnScriptTagHelper : ScriptTagHelper<CdnTagHelperOptions>, ITagHelper, ITagHelperComponent, IConfigurable<CdnTagHelperOptions>
- Inheritance
-
CdnScriptTagHelper
- Implements
- Inherited Members
Examples
The following example demonstrates how to create CdnScriptTagHelper with CDN-specific options.
using System;
using Cuemon.AspNetCore.Configuration;
using Cuemon.AspNetCore.Razor.TagHelpers;
using Microsoft.Extensions.Options;
namespace MyApp.Examples;
public static class CdnScriptTagHelperExample
{
private sealed class ScriptVersion : ICacheBusting
{
public string Version => "1.0.0";
}
public static void Demonstrate()
{
var options = Options.Create(new CdnTagHelperOptions
{
Scheme = ProtocolUriScheme.Https,
BaseUrl = "nblcdn.net"
});
var cacheBusting = new ScriptVersion();
var tagHelper = new CdnScriptTagHelper(options, cacheBusting)
{
Src = "packages/fontawesome/5.15.3/js/all.js",
Defer = true
};
var scriptPath = string.Concat(tagHelper.Options.GetFormattedBaseUrl(), tagHelper.Src, "?v=", cacheBusting.Version);
Console.WriteLine(scriptPath);
}
}
Constructors
| Name | Description |
|---|---|
| CdnScriptTagHelper(IOptions<CdnTagHelperOptions>, ICacheBusting) | Initializes a new instance of the CdnScriptTagHelper class. |
See Also
ScriptTagHelper<TOptions>