<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-i-use-htmx-with-go-alex-edwards-yu7zybtpn" -->

---
title: How I use HTMX with Go– Alex Edwards | daily.dev
description: A practical guide to integrating HTMX with Go web applications, covering HTML template structuring (base, pages, partials), embedding assets with Go's embed...
canonical: https://daily.dev/posts/how-i-use-htmx-with-go-alex-edwards-yu7zybtpn
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How I use HTMX with Go– Alex Edwards | daily.dev
og:description: A practical guide to integrating HTMX with Go web applications, covering HTML template structuring (base, pages, partials), embedding assets with Go's embed...
og:url: https://daily.dev/posts/how-i-use-htmx-with-go-alex-edwards-yu7zybtpn
og:image: https://api.daily.dev/og/posts/YU7ZybtPN.png
og:image:alt: How I use HTMX with Go– Alex Edwards
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How I use HTMX with Go– Alex Edwards

**[Alex Edwards](https://daily.dev/sources/alexedwards)** · 21 min read · 10 upvotes · 0 comments

## Summary

A practical guide to integrating HTMX with Go web applications, covering HTML template structuring (base, pages, partials), embedding assets with Go's embed package, rendering full-page vs partial HTML responses, detecting HTMX requests via the HX-Request header, handling redirects with HX-Redirect vs HX-Location, configuring error response handling, managing back-button behavior with history cache settings, and recommended HTMX configuration options like disabling attribute inheritance and local storage caching.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.alexedwards.net/blog/how-i-use-htmx-with-go>

## Questions this post answers

### How do I redirect to a new page after a form submission when using HTMX with Go?

Send a 2xx response with an HX-Redirect header set to the target URL instead of a normal 3xx response, because browsers intercept 3xx responses before HTMX can see them. The HX-Redirect header tells HTMX to make the browser navigate to that URL with a full-page reload, and the HX-Request header will not be present on that follow-up request. Fall back to a regular 3xx response when the request isn't coming from HTMX.

_Developers wiring up HTMX redirects in Go handlers can find worked patterns like this one on daily.dev._

### How can I tell in a Go handler whether a request came from HTMX so I can return a partial instead of a full page?

Check for the HX-Request: true header on the incoming request, which HTMX always includes on requests it makes. A helper function like isHTMXRequest() can inspect this header, letting a handler branch between returning an HTML partial for HTMX swaps and a full HTML page for direct browser visits or shared links. Also set a Vary: HX-Request header on responses to avoid caching issues.

_Building HTMX-aware Go handlers gets easier with concrete request-detection patterns shared on daily.dev._

### Why does the HTMX back button show a partial HTML fragment instead of the full page after a cache miss?

By default HTMX caches up to 10 pages in local storage, but on a cache miss it resends the request including an HX-Request: true header, causing servers that conditionally return partials to send back only a fragment. Setting historyRestoreAsHxRequest to false in the HTMX config stops that header from being sent on history-restore requests, so the server returns the full page instead.

_Anyone debugging HTMX back-button quirks in a Go app can compare configuration fixes on daily.dev._

## Similar posts on daily.dev

- [A deep dive into HTMX](https://daily.dev/posts/a-deep-dive-into-htmx-uuhadafnq) · Flavio Copes · 1 upvotes · 0 comments
- [Please Just Fucking Try HTMX](https://daily.dev/posts/please-just-fucking-try-htmx-ncu8zbk1v) · Lobsters · 21 upvotes · 3 comments
- [HTMX Is So Cool I Rolled My Own\!](https://daily.dev/posts/htmx-is-so-cool-i-rolled-my-own--ocvhcvgx1) · Lobsters · 28 upvotes · 4 comments

---

Tags: [#webdev](https://daily.dev/tags/webdev), [#golang](https://daily.dev/tags/golang), [#htmx](https://daily.dev/tags/htmx)

[View this post on daily.dev](https://daily.dev/posts/how-i-use-htmx-with-go-alex-edwards-yu7zybtpn)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How I use HTMX with Go– Alex Edwards","url":"https://daily.dev/posts/how-i-use-htmx-with-go-alex-edwards-yu7zybtpn","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-i-use-htmx-with-go-alex-edwards-yu7zybtpn"},"datePublished":"2026-07-14T12:02:15.379Z","dateModified":"2026-09-14T08:52:40.803Z","description":"A practical guide to integrating HTMX with Go web applications, covering HTML template structuring (base, pages, partials), embedding assets with Go's embed...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d3626e01697ecafc6d423ea86e659a11?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d3626e01697ecafc6d423ea86e659a11?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Alex Edwards","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Alex Edwards","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/18a312a174d74e40910caa528ca8d072","url":"https://daily.dev/sources/alexedwards"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-i-use-htmx-with-go-alex-edwards-yu7zybtpn","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":10},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"webdev,golang,htmx","timeRequired":"PT21M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Alex Edwards","item":"https://daily.dev/sources/alexedwards"},{"@type":"ListItem","position":3,"name":"How I use HTMX with Go– Alex Edwards"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-i-use-htmx-with-go-alex-edwards-yu7zybtpn#faq","mainEntity":[{"@type":"Question","name":"How do I redirect to a new page after a form submission when using HTMX with Go?","acceptedAnswer":{"@type":"Answer","text":"Send a 2xx response with an HX-Redirect header set to the target URL instead of a normal 3xx response, because browsers intercept 3xx responses before HTMX can see them. The HX-Redirect header tells HTMX to make the browser navigate to that URL with a full-page reload, and the HX-Request header will not be present on that follow-up request. Fall back to a regular 3xx response when the request isn't coming from HTMX. Developers wiring up HTMX redirects in Go handlers can find worked patterns like this one on daily.dev."}},{"@type":"Question","name":"How can I tell in a Go handler whether a request came from HTMX so I can return a partial instead of a full page?","acceptedAnswer":{"@type":"Answer","text":"Check for the HX-Request: true header on the incoming request, which HTMX always includes on requests it makes. A helper function like isHTMXRequest() can inspect this header, letting a handler branch between returning an HTML partial for HTMX swaps and a full HTML page for direct browser visits or shared links. Also set a Vary: HX-Request header on responses to avoid caching issues. Building HTMX-aware Go handlers gets easier with concrete request-detection patterns shared on daily.dev."}},{"@type":"Question","name":"Why does the HTMX back button show a partial HTML fragment instead of the full page after a cache miss?","acceptedAnswer":{"@type":"Answer","text":"By default HTMX caches up to 10 pages in local storage, but on a cache miss it resends the request including an HX-Request: true header, causing servers that conditionally return partials to send back only a fragment. Setting historyRestoreAsHxRequest to false in the HTMX config stops that header from being sent on history-restore requests, so the server returns the full page instead. Anyone debugging HTMX back-button quirks in a Go app can compare configuration fixes on daily.dev."}}]}
```

