cdn

package
v1.27.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package cdn provides shared CDN URL helpers for runtime libraries (HTMX, Datastar, etc.). Both layout and datastar need the same logic: default a base URL when empty, trim trailing slashes, and extract the scheme+host (origin) for <link rel="preconnect">. Centralizing the helpers prevents drift between the two packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Origin

func Origin(cdnBase, defaultBase string) string

Origin extracts the scheme+host (origin) from the CDN base URL for use in <link rel="preconnect">. Returns "" if the input doesn't parse as an absolute URL (e.g. a relative self-hosted path like "/assets").

The scheme prefix is fixed at 8 characters to match both "http://" and "https://" — both are 7 chars plus the colon-slash-slash.

cdn.Origin("https://cdn.jsdelivr.net/npm") -> "https://cdn.jsdelivr.net"
cdn.Origin("https://unpkg.com/foo")        -> "https://unpkg.com"
cdn.Origin("/assets")                      -> ""

func ResolveBase

func ResolveBase(cdnBase, defaultBase string) string

ResolveBase returns cdnBase if non-empty, otherwise defaultBase. A trailing slash is trimmed so consumers can pass "https://unpkg.com/" safely. The fallback default is the package default (e.g. jsDelivr).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL