Documentation
¶
Overview ¶
Package link provides constructors and methods for the HTML <link> element.
The <link> HTML element specifies relationships between the current document and external resources. Primarily used for linking stylesheets, establishing site icons (favicons and app icons), and resource preloading/prefetching. Appears in the document head. Essential for applying styles, setting page icons, optimising resource loading, and establishing document relationships.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( TagOpen = []byte("<link") AttrRel = []byte(" rel=\"") AttrHref = []byte(" href=\"") AttrAs = []byte(" as=\"") AttrCrossOrigin = []byte(" crossorigin=\"") AttrDisabled = []byte(" disabled") AttrHrefLang = []byte(" hreflang=\"") AttrIntegrity = []byte(" integrity=\"") AttrMedia = []byte(" media=\"") AttrReferrerPolicy = []byte(" referrerpolicy=\"") AttrSizes = []byte(" sizes=\"") AttrTitle = []byte(" title=\"") AttrType = []byte(" type=\"") AttrFetchPriority = []byte(" fetchpriority=\"") AttrBlocking = []byte(" blocking=\"") AttrImageSrcset = []byte(" imagesrcset=\"") AttrImageSizes = []byte(" imagesizes=\"") AttrColor = []byte(" color=\"") )
Byte constants for HTML rendering.
Functions ¶
func Canonical ¶ added in v0.3.0
func Canonical(href string) *element
Canonical creates a link element declaring the canonical URL for the page. Important for SEO when the same content is accessible at multiple URLs. Search engines use this to consolidate ranking signals. Example: link.Canonical("https://example.com/page") Renders: <link rel="canonical" href="https://example.com/page" />
func Icon ¶
func Icon(href string) *element
Icon creates a new link element for a site icon (favicon). Example: link.Icon("/favicon.ico") Renders: <link rel="icon" href="/favicon.ico" />
func New ¶
func New() *element
New creates a new link element without any initial attributes. Example: link.New() Renders: <link />
func Prefetch ¶ added in v0.3.0
func Prefetch(href string) *element
Prefetch creates a link element that hints the browser to prefetch a resource the user is likely to navigate to next. The resource is fetched at low priority during idle time and cached for future use. Example: link.Prefetch("/next-page") Renders: <link rel="prefetch" href="/next-page" />
func Preload ¶
Preload creates a new link element for preloading resources to improve performance. Example: link.Preload("/font.woff2", as.Font) Renders: <link rel="preload" href="/font.woff2" as="font" />
func Stylesheet ¶
func Stylesheet(href string) *element
Stylesheet creates a new link element for a CSS stylesheet. Example: link.Stylesheet("/styles.css") Renders: <link rel="stylesheet" href="/styles.css" />