Use case: JavaScript service worker development with multiple tabs/clients where you don’t want automatic browser reloads or posts.
Local dev servers with automatic browser reloads or posts can be problematic when developing service workers with multiple clients. For example, you want to test a scenario by posting messages on one client (single browser tab) and broadcasting to the same or all clients (multiple open tabs). With automatic browser reloads the post might happen on all clients (all browser tabs) and debugging can be elusive. You might have the same URL open in 2 different tabs and a post on one tab might trigger the post on the other tab as well with some automatic reload dev servers.
The solution is to use a server that doesn’t do automatic reloads or posts. Instead of installing one, you can just write your own.
Here is a trivial 2-line Go server that you can use to serve your static HTML, CSS and JavaScript files locally. Though it looks more than 2 lines, it’s essence are these 2 functions: http.Handle for pattern “/” for current folder to be used as a file server and running the server with http.ListenAndServe on port 3000.
package main
import (
"fmt"
"log"
"net/http"
)
func main() {
fs := http.FileServer(http.Dir("."))
http.Handle("/", http.StripPrefix("/", fs))
fmt.Println("running server on port 3000...")
log.Fatal(http.ListenAndServe(":3000", nil))
}
If you are on Windows, you can download the executable file and run it on the root level directory of your source code. For example:

Files:
- Source code: server.go
- Windows exe: server.exe
