Go Modest
Github: https://github.com/adnaan/gomodest
GOMODEST is a Multi Page App(MPA) starter kit using Go’s html/template
, SvelteJS
and StimulusJS
. It is inspired from modest approaches to building webapps as enlisted in https://modestjs.works/. It can be used as a template to spin off simple Go webapps.
Motivation
I am a devops engineer who dabbles in UI for side projects, internal tools and such. The SPA/ReactJS ecosystem is too costly for me. This is an alternative approach.
The main idea is to use server rendered html with spots of client-side dynamism using SvelteJS & StimulusJS
The webapp is mostly plain old javascript, html, css but with sprinkles of StimulusJS & spots of SvelteJS used for interactivity sans page reloads. StimulusJS is used for sprinkling interactivity in server rendered html & mounting Svelte components into divs.
Stack
A few things which were used:
- Go, html/template, goview
- Authentication: github.com/adnaan/users
- SvelteJS
- StimulusJS
- Bulma CSS
Many more things in go.mod
& web/package.json
To run, clone this repo and:
|
|
The ideas in this starter kit follow the JS gradient as noted here. I have taken the liberty to organise them into the following big blocks: server-rendered html, sprinkles and spots.
Server Rendered HTML
Use html/template
and goview
to render html pages. It’s quite powerful when do you don’t need client-side interactions.
example:
|
|
Sprinkles
Use stimulusjs
to level up server-rendered html to handle simple interactions like: navigations, form validations etc.
example:
|
|
|
|
Spots
Use sveltejs
to take over spots
of a server-rendered html page to provide more complex interactivity without page reloads.
This snippet is the most interesting part of this project:
|
|
In the above snippet, we use StimulusJS to mount a Svelte component by using the following code:
|
|
This strategy allows us to mix server rendered HTML pages with client side dynamism.
Other possibly interesting aspects could be the layout of web/html and the usage of the super nice goview library to render html in these files:
That is all.