Table of Contents

Class CdnScriptTagHelper

Namespace
Cuemon.AspNetCore.Razor.TagHelpers
Assembly
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);
        var scriptPath = string.Concat(options.Value.GetFormattedBaseUrl(), "packages/fontawesome/5.15.3/js/all.js?v=", cacheBusting.Version);

        Console.WriteLine(scriptPath);
        Console.WriteLine(tagHelper.GetType().Name);
    }
}

Constructors

CdnScriptTagHelper(IOptions<CdnTagHelperOptions>, ICacheBusting)

Initializes a new instance of the CdnScriptTagHelper class.

public CdnScriptTagHelper(IOptions<CdnTagHelperOptions> setup, ICacheBusting cacheBusting = null)

Parameters

setup IOptions<CdnTagHelperOptions>

The CdnTagHelperOptions which need to be configured.

cacheBusting ICacheBusting

An optional object implementing the ICacheBusting interface.

See Also

ScriptTagHelper<TOptions>