Package: cdn

Easy helpers for including popular frontend libraries via CDN in Go UIs.

Package: cdn

Easy helpers to include popular frontend libraries via CDN in Go UIs.
Supports Bootstrap, Tailwind, FontAwesome, HTMX, jQuery, DataTables,
Google Fonts, and more.

Why use this package?

Using CDN packages directly has many advantages:

  • No need to download and host files
  • No extra build steps (no need to compile SCSS, minify JS, etc.)
  • Automatic updates
  • Faster delivery
  • Reduced server load

Install

go get github.com/gouniverse/cdn@latest

Quick Start

import (
    "github.com/gouniverse/cdn"
    "github.com/gouniverse/hb"
)

func Head() hb.TagInterface {
    return hb.Wrap().
        Child(hb.Link().Rel("stylesheet").Href(cdn.BootstrapCss_5_3_3())).
        Child(hb.Script().Src(cdn.BootstrapJs_5_3_3()))
}

Common Assets

  • Bootstrap CSS/JS: cdn.BootstrapCss_5_3_3(), cdn.BootstrapJs_5_3_3()
  • Tailwind: cdn.TailwindCss_3_4_4()
  • FontAwesome: cdn.FontAwesomeCss_6_4_2()
  • HTMX: cdn.Htmx_2_0_0()
  • jQuery: cdn.Jquery_3_7_1()
  • DataTables: cdn.JqueryDataTablesCss_1_13_4(), cdn.JqueryDataTablesJs_1_13_4()
  • Google Fonts: cdn.GoogleFont("Josefin Sans", "300,400,500")

Custom CDN Prefix

Set a custom prefix with CDN_URL_PREFIX env var:

export CDN_URL_PREFIX="https://mycustomcdn.example.com/"

In Layouts

head := hb.Wrap().
    Child(hb.Link().Rel("stylesheet").Href(cdn.BootstrapCss_5_3_3()))
body := hb.Script().Src(cdn.BootstrapJs_5_3_3())
Menu