What's Isomorphic Go?

Isomorphic Go is the methodology to create isomorphic web applications using the Go programming language.

Isomorphic web applications, are applications where the web server and the web browser (the client), may share all, or some parts of the web application code. Isomorphic web applications allow you to reap the maximum benefits from traditional web application architectures. They provide a better user experience, enhanced discoverability by search engines, and reduced operating costs by sharing parts of the web application code across environments.

Here's a live demo of IGWEB, a web application created with Isomorphic Go. You can obtain the source code for the entire demo, and learn how to run it locally here.

Here's an example of an Isomorphic Buffalo App created by Brian Ketelsen. Watch the video demonstrating the rendering of templates on both the server-side and the client-side.

The major benefits that Isomorphic Go provides

High Performance

On the server-side, Go code gets compiled to a native binary, and the machine executes it. There is no virtual machine eating up extra CPU cycles.

Search Engine Friendly

Isomorphic Go web apps provide the capability to define pretty URLs that can be easily indexed along with well-formed HTML content, that's readily consumable by bot crawlers.

Powerful Tooling

The Isomorphic Go toolkit provides powerful tooling to implement common functionality found in isomorphic web apps, such as client-side routing, isomorphic template rendering, and creating isomorphic web forms.

Why make isomorphic web apps with Go?

JavaScript has been the most popular option to create truly isomorphic web applications. Now, a new option exists in Isomorphic Go.

Go is a modern programming language that's designed to be relevant in an age of multi-core processors and distributed systems. Unlike Node.js, back-end web server instances implemented in Go, are multi-threaded, using cheap, lightweight threads known as goroutines. Go's powerful concurrency constructs allow you to avoid callback hell, enabling you to create code that is more maintainable.

"If you're building a server, I can't imagine using anything other than Go."
— Ryan Dahl, Creator of Node.js

Go is a statically typed language unlike popular scripting languages such as JavaScript, Python, Ruby, and PHP. As a statically typed language, Go comes with the advantage that many problems can be discovered at compile time. The language also comes with type inference capabilities, giving Go the feel of a dynamic programming language along with the added benefit of type safety.

Go includes many features that allow developers to be highly productive. Go has a simple and terse syntax which promotes readability and maintainability. Go has an implicit build system, that automates dependency analysis, which eliminates the need to manually create and maintain build files. Go comes with a robust standard library, providing a lot of useful functionality, right out of the box.

Having a single, unified Go codebase, eliminates the mental context-shifts that come with juggling between two different programming languages on the back-end (Go, PHP, Java, Python, Ruby, etc) and the front-end (JavaScript). Isomorphic Go makes it possible to share parts of the application codebase, between the client and the server, allowing you to reuse code and avoid repetition.


Learn Isomorphic Go

Learn how to build isomorphic web applications using the Go programming language by reading the Isomorphic Go book, by Kamesh Balasubramanian. Foreword by Mat Ryer, Founder of Machine Box.

This book focuses on teaching you how to create an Isomorphic Go web application from the ground up. This book is a journey starting out with presenting the advantages of creating an isomorphic web application with Go, and ending with the deployment of a multi-container Isomorphic Go web application to the cloud.

What the Book Covers

The Isomorphic Go book begins with an in-depth exploration of the benefits provided by the isomorphic web application architecture. The reader is introduced to the Isomorphic Go toolchain, and how it can be utilized to write Go code that functions across environments. The reader will also learn how to create Go programs in the web browser using GopherJS, render isomorphic templates, perform end-to-end application routing, use isomorphic handoff to seamlessly transition state from the web server to the web browser, and compose isomorphic forms that have the ability to re-use form validation logic. The reader will also be exposed to advanced concepts including the implementation of real-time web application functionality with websockets, the creation of reusable components (cogs) that are rendered using the virtual DOM, and finally, the reader will learn how to deploy an Isomorphic Go web application to a production environment.

What You Will Learn

The Isomorphic Go toolkit

The isokit package provides common isomorphic functionality, including isomorphic template rendering and end-to-end application routing.

Kick is a lightweight mechanism to provide an instant kickstart to a Go web server instance, upon the modification of a Go source file within a particular project directory (including any subdirectories). An instant kickstart consists of a recompilation of the Go code and a restart of the web server instance. Kick comes with the ability to take both the go and gopherjs commands into consideration when performing the instant kickstart. This makes it a really handy tool for isomorphic golang projects.


The features provided by Isomorphic Go promote greater synergy between the server and the client. Here's a partial list of features:

Isomorphic Template Rendering

Isomorphic Go provides isomorphic template rendering, which allows you to utilize Go templates across environments. That means that the same Go template can be rendered either on the server-side, or on the client-side. In additon to being able to share templates across environments, Isomorphic Go, also allows you to share template data objects and template functions as well.


<div id="gopherTeamContainer">
  {{range .Gophers}}

    <div class="gopherContainer">

      <div class="gopherImageContainer">
        <img height="270" src="{{.ImageURI}}">

      <div class="gopherDetailsContainer">
          <div class="gopherName"><h3><b>{{.Name}}</b></h3></div>
          <div class="gopherTitle"><span>{{.Title}}</span></div> 
          <div class="gopherBiodata"><p>{{.Biodata}}</p></div>
          <div class="gopherStartTime">
            <p class="standardStartTime">{{.Name}} joined the IGWEB team on <span class="starttime">{{.StartTime}}.</p>
            <p class="rubyStartTime">That's <span class="starttime">{{.StartTime | rubyformat}}</span> in Ruby date format.</p>
            <div class="humanReadableGopherTime">That's
				<div id="Gopher-{{.Name}}" data-starttimeunix="{{.StartTime | unixformat}}" data-component="cog" class="humanReadableDate starttime"></div>
				in Human readable format.



End-to-end Routing

End-To-End Routing allows you to create web applications that are optimized for both human users and machine users (search engine bot crawlers). Isomorphic Go provides dynamic client-side routing, enhancing the human user experience by ensuring your web application runs in single page mode for subsequent user interactions. Dynamic client-side routing, also enables you to match server-side routes, and create pretty URLs that can be easily indexed by search engines.

func registerRoutes(env *common.Env) {

	r := isokit.NewRouter()
	r.Handle("/index", handlers.IndexHandler(env))
	r.Handle("/products", handlers.ProductsHandler(env))
	r.Handle("/product-detail/{productTitle}", handlers.ProductDetailHandler(env))
	r.Handle("/about", handlers.AboutHandler(env))
	r.Handle("/contact", handlers.ContactHandler(env))
	r.Handle("/shopping-cart", handlers.ShoppingCartHandler(env))
	env.Router = r


Isomorphic Web Forms

In addition to promoting greater accessiblity, isomorphic web forms provide the ability to share validation logic and form structure across environments. The isomorphic web form will function for the most stripped down, text-only web client, that has no JavaScript runtime, as well as the GUI-based web client equipped with the latest JavaScript runtime.


Automated End-to-End Testing

Isomorphic Go allows you to perform automated, end-to-end testing to exercise both server-side and client-side functionality. Using CasperJS, you can create tests that verify multiple user interaction scenarios and you can generate screenshots to visually review the results of individual tests. The tests are first written in Go, and then converted into JavaScript, using GopherJS.


Watch the talk on Isomorphic Go

Kamesh Balasubramanian presents the advantages of programming in Go on both the back-end and the front-end. He introduces basic concepts of client-side Go using GopherJS and then goes on to demonstrate how to build a basic 3D scene using GopherJS and a 3D JavaScript library.

He also shows how to port a command line web socket client intended to run on the command line back to where it belongs - in the web browser. Kamesh covers the basics of using Go's template package to do client side rendering and finishes off by explaining the benefits of using package encoding/gob for data exchange needs in a Go-specific environment.