agentleFS
bmcszkbmcszk/agent-skills/skills/go-htmx-frontend/SKILL.md

go-htmx-frontend

Skill1 starsChanged 2 months agoMITView on GitHub

Server-side frontend development with Go, HTMX, and Templ - type-safe, minimal JavaScript. Use when building web UIs with Go using Templ components, HTMX 2.x for interactivity, Tailwind CSS v4, or Alpine.js. Covers installation, syntax, HTMX integration, forms, handlers, streaming, testing, and deployment. Keywords: htmx, templ, go frontend, server-side rendering, tailwind css, alpine js, web development.

  • Installs packages

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No dependency management overhead

    line 70
  2. Very specific:

    No Node.js: Use Tailwind standalone CLI, not npm

    line 310
  3. Distinctive:

    Check Docs: Always verify with official documentation

    line 312

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

What I Do

Build web UIs with Go using:

  • Templ: Type-safe HTML components
  • HTMX 2.x: Hypermedia-driven interactivity
  • Tailwind CSS v4: CSS-first styling
  • Alpine.js: Client state (when needed)

Official Documentation

ALWAYS check these sources:


Installation

Templ

# Templ CLI (Go 1.24+)
go install github.com/a-h/templ/cmd/templ@latest

# Or as project tool
go get -tool github.com/a-h/templ/cmd/templ@latest

# Go dependencies
go get github.com/a-h/templ

Tailwind CSS v4 (Standalone CLI - No Node.js Required)

IMPORTANT: Use the standalone CLI for Go projects. Do NOT use npm/Node.js.

# Download standalone CLI (Linux/macOS)
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-$(uname -m)-unknown-linux-gnu -o tailwindcss
chmod +x tailwindcss
sudo mv tailwindcss /usr/local/bin/

# Or install to project tools directory
mkdir -p tools
curl -sL https://github.com/tailwindlabs/tailwindcss/releases/latest/download/tailwindcss-$(uname -m)-unknown-linux-gnu -o tools/tailwindcss
chmod +x tools/tailwindcss

Why Standalone CLI over npm:

  • No node_modules folder
  • No package.json / package-lock.json
  • Single binary download
  • Cleaner project structure
  • Faster builds (v4 is 5x faster)
  • No dependency management overhead

HTMX

# Download HTMX 2.x to static folder
mkdir -p static/js
curl -sL https://unpkg.com/htmx.org@2/dist/htmx.min.js -o static/js/htmx.min.js

Alpine.js (Optional - for client state)

curl -sL https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js -o static/js/alpine.min.js

References

Specialized topics are split into focused reference files:

  • Templ — Type-safe HTML components, composition, loops, conditionals
  • HTMX — Form partials, patterns, loading states, hx-on events
  • Tailwind CSS v4 — Standalone CLI, @source directives, build commands
  • Forms & Validation — View models, form templates, CSRF protection
  • Deployment & Build — justfile, CI, build commands, production config

HTTP Handlers

Static Pages with templ.Handler

// main.go
package main

import (
    "net/http"
    "github.com/a-h/templ"
)

func main() {
    http.Handle("/", templ.Handler(HomePage()))
    http.Handle("/404", templ.Handler(NotFound(), templ.WithStatus(http.StatusNotFound)))
    http.ListenAndServe(":8080", nil)
}

Dynamic Data with Render

// handler.go
package main

import (
    "net/http"
    "time"
)

type NowHandler struct {
    Now func() time.Time
}

func (nh NowHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    // Use Render for dynamic data
    ShowTime(nh.Now()).Render(r.Context(), w)
}

func main() {
    http.Handle("/", NowHandler{Now: time.Now})
    http.ListenAndServe(":8080", nil)
}

HTMX-Aware Handler

func (h *Handler) GetUser(w http.ResponseWriter, r *http.Request) {
    id := chi.URLParam(r, "id")
    
    user, err := h.service.GetUser(r.Context(), id)
    if err != nil {
        w.WriteHeader(http.StatusNotFound)
        NotFound().Render(r.Context(), w)
        return
    }
    
    // Check if HTMX request
    if r.Header.Get("HX-Request") == "true" {
        // Return partial only
        UserRow(user).Render(r.Context(), w)
    } else {
        // Return full page
        UserPage(user).Render(r.Context(), w)
    }
}

Context for Prop Drilling

From official docs: https://templ.guide/syntax-and-usage/context/

Type-Safe Context Access

// context.go
type contextKey string

var themeContextKey contextKey = "theme"

func GetTheme(ctx context.Context) string {
    if theme, ok := ctx.Value(themeContextKey).(string); ok {
        return theme
    }
    return ""
}
// component.templ
templ ThemeDisplay() {
    <div>{ GetTheme(ctx) }</div>
}

HTTP Middleware for Context

func ThemeMiddleware(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        ctx := context.WithValue(r.Context(), themeContextKey, "dark")
        next.ServeHTTP(w, r.WithContext(ctx))
    })
}

HTTP Streaming

From official docs: https://templ.guide/server-side-rendering/streaming/

Enable Streaming

templ.Handler(component, templ.WithStreaming()).ServeHTTP(w, r)

Streaming with Flush

templ StreamingPage(data chan string) {
    <!DOCTYPE html>
    <html>
        <head><title>Streaming</title></head>
        <body>
            <h1>Streaming Page</h1>
            for d := range data {
                @templ.Flush() {
                    <div>{ d }</div>
                }
            }
        </body>
    </html>
}

Suspense Pattern with Shadow DOM

templ Slot(name string) {
    <slot name={ name }>
        <div>Loading { name }...</div>
    </slot>
}

templ SuspensePage(data chan SlotContents) {
    <!DOCTYPE html>
    <html>
        <head><title>Suspense</title></head>
        <body>
            @templ.Flush() {
                <template shadowrootmode="open">
                    @Slot("a")
                    @Slot("b")
                </template>
            }
            for sc := range data {
                @templ.Flush() {
                    <div slot={ sc.Name }>
                        @sc.Contents
                    </div>
                }
            }
        </body>
    </html>
}

Testing

Component Test

func TestHello(t *testing.T) {
    var buf bytes.Buffer
    err := Hello("World").Render(context.Background(), &buf)
    
    require.NoError(t, err)
    assert.Contains(t, buf.String(), "Hello, World!")
}

Handler Test with HTMX

func TestHandler(t *testing.T) {
    req := httptest.NewRequest("GET", "/users", nil)
    req.Header.Set("HX-Request", "true")
    
    rr := httptest.NewRecorder()
    handler.ServeHTTP(rr, req)
    
    assert.Equal(t, http.StatusOK, rr.Code)
}

Key Principles

  1. Server-First: Render HTML server-side
  2. Type Safety: Templ validates at compile time
  3. Minimal JS: Alpine.js only for client state
  4. Progressive Enhancement: Works without JS
  5. No Node.js: Use Tailwind standalone CLI, not npm
  6. CSS-First Config: Tailwind v4 uses @theme in CSS, no JS config
  7. Check Docs: Always verify with official documentation

Resources

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.