Web Apps (Server-Side Rendering)
Building systems with Go rather than JavaScript
Data scientists and data engineers are more productive when they can focus on the backend, accessing databases and working with analytic methods and models. The less frontend programming in JavaScript or TypeScript, the better.
With Go, web applications can be developed on the backend with server-side rendering. There is the html/template package from the Go standard library, and there are third-party templating packages.
Go web app developers can also utilize htmx (HTML extension), building on the original promise of hypertext and hypermedia, as reviewed by Gross, Stepinski, and Akşimşek (2023).
Serdar Yegulalp of Dev with Serdar provides this five-minute overview with examples: Htmx: Faster, and simpler, interactive web apps.
With htmx, developers can add dynamic interaction to web apps, responding to client activity on the browser. Curiously, these developers are using the power of JavaScript without actually programming in JavaScript. This is because htmx is a dependency free, stand-alone JavaScript library that takes full advantage of hypermedia. Htmx is generating interest among web developers, as shown by this Dev Community posting: Why you should choose HTMX for your next project.
How does htmx work? It uses HTML attributes, swapping out elements within an HTML page. Server-side rendering with htmx sends partial (rather than full) HTML pages in response to client requests. This has performance advantages over server-side rendering without htmx.
A September 2020 devMode.fm podcast with Carson Gross, the creator of htmx, reviewed the capabilities of the library. The awesome-htmx repository lists applications of htmx across many languages and development environments.
The Go Time podcast Is htmx the way to Go? had Carson Gross join Chris James, David Wickes, and Jon Calhoun. They reviewed more than thirty years of web programming history, comparing backend- and frontend-focused approaches. Here is the recording from February 2023:
The dominant approach to web development today is frontend-focused. Companies choose a frontend framework, and that choice dominates subsequent technology choices. JavaScript on the frontend suggests Node.js on the backend. React begets Next.js. Svelte begets SvelteKit.
Today’s web app developers find themselves on a perpetual treadmill, trying to keep up with the latest technology trends. From Javascript to TypeScript, from REST to GraphQL, from Node.js to Deno—staying up to date and code refactoring become a full-time job.
Consider a backend-focused approach with Go and server-side rendering. Consider an approach to web app development that offers simplicity and continuity. Technology improves with time. Performance improves. New features become available. But, given Go’s backward compatibility at the source code level, refactoring of code repositories is by choice, not necessity.
A key benefit of server-side rendering is its continuity. As an approach to web development, server-side rendering has been relatively stable over the last thirty years. What we learn today about Go templates and HTML will be relevant for many years to come.
Another benefit of server-side rendering comes as a byproduct of website structure. Web apps built from the server side are multi-page apps, whereas web apps built with frontend frameworks are single-page apps. Multi-page apps, by definition, have more pages than single-page apps, so they are easier to discover when users search for information. Search engine optimization (SEO) is important to most applications, and server-side, multi-page web apps exhibit superior SEO performance.
Server-side rendering, what had been the primary approach to web development thirty years ago, could have a new life as a robust alternative to web development dominated by frontend frameworks.
With its tools for http communications, its strength as a backend development platform, and the possibilities of server-side rendering and htmx, Go provides a rich environment for web app development. Much can be accomplished with Go.
References #
-
Bodner, Jon. 2024. Learning Go: An Idiomatic Approach to Real-World Go Programming (second edition). Sebastopol, CA: O’Reilly. [ISBN-13: 978-1098139292] Program repositories available from GitHub. Chapter 13 reviews the Go standard library, including server routing updates to the http.net package as part of Go 1.22.
-
Calhoun, Jon. 2023. An Introduction to Templates in Go. reviews the Go standard library http/template.
-
Chang, Sau Sheong. 2016. Go Web Programming. Shelter Island, NY: Manning. [ISBN-13: 978-1617292569] Code is available from the book’s GitHub repository. The author’s GitHub user site has more than one hundred public repositories, including a repository for a potential second edition of this book.
-
Saha, Amit. 2022. Practical Go: Building Scalable Network & Non-network Applications. New York: Wiley. [ISBN-13: 978-1-119-77381-8] Code, exercise solutions, and a glossary are available for download at the book’s website and GitHub repository.
-
Woodbeck, Adam. 2021. Network Programming with Go: Code Secure and Reliable Network Services from Scratch. San Francisco: No Starch Press. [ISBN-13: 978-1-7185-0088-4] Code is available from the book’s GitHub repository.
Of Special Interest #
- Gross, Carson, Adam Stepinski, and Deniz Akşimşek. 2023. Hypermedia Systems. Independently published. [ISBN-13: 979-8394025143]
Back to Building Systems and Services