Comments (2)
Ah, the idea of out-of-order flushing of async fragments is quite clever.
I've been focused on the idea of using https://hotwired.dev/ to achieve similar goals, and so templ has built in support for that. Perhaps it will meet your needs?
The idea is that you compose the page out of "frames", and you can simply point a frame at a HTTP endpoint. This is managed by a small amount of client side script made by the Hotwire folks.
I made a tiny example at https://github.com/a-h/microfrontend
In the example, the src
attribute on the turbo-frame
is picked up by the Hotwire JavaScript library, loads the remote content, and applies it to the page.
<turbo-frame id="article" src="/article/123">
Loading article (it takes 5 seconds)
</turbo-frame>
The web server has a route of /article
which then gets invoked. As an example, I've put a 5 second wait in, so that you can see the content loading.
type articleContent struct{}
func (ac articleContent) Render(ctx context.Context, w io.Writer) error {
_, err := io.WriteString(w, `This is the async loaded content`)
return err
}
func articleHandler(w http.ResponseWriter, r *http.Request) {
time.Sleep(time.Second * 5)
turbo.ReplaceWithContext(r.Context(), w, "article", articleContent{})
}
func main() {
h := http.NewServeMux()
h.Handle("/article/", http.HandlerFunc(articleHandler))
h.Handle("/", templ.Handler(home()))
http.ListenAndServe("localhost:8000", h)
}
It's possible (and in fact, part of the design) to use Turbo streams with a web socket for remote loading of content etc.
What do you think?
from templ.
Brilliant, cheers the example + repo is great.
I also think turbo streams + server side events would be a great combo that I need to look into. Turbo helpers being built into templ is sweet I missed that.
Aside: what is great about using Go for the /article endpoint is that even though you are doing a sleep for 5 seconds, it will only block a goroutine and not a full thread. Not many languages have that simplicity yet and require a lot of gymnastics.
Hotwire is great, lives in the realm of Unpoly/HTMX. Paired with Stimulus and you can get very far, + templ brilliantly solves the ability to 'componentize' the frontend like you would in React/Svelte. For complex frontend apps SPA is the goto but 99% could be using this setup!
from templ.
Related Issues (20)
- cmd: `templ generate --watch` don't end `-cmd` on `ctrl+c` HOT 2
- question: How to pass JavaScript `arguments` to a script component? HOT 3
- cmd: Proxy flag is causing WSL to open browser using x11 forwarding. Causing terminal to pause logs. HOT 7
- lsp: Add HTML Intellisense Support to Templ LSP HOT 16
- vscode: Missing color syntax for @ templ elements HOT 2
- scripts: js minify HOT 7
- parser: error when a template with arguments on new lines comes after go code HOT 3
- css: rotation transform getting sanitized HOT 5
- vscode: Inconsistent syntax highlighting in vscode. HOT 3
- Cannot render in Docker HOT 6
- tests: templ generate exits with 0 when there are errors HOT 6
- Error Installing on windows 10 HOT 2
- Lack of proper CSS handling? HOT 1
- vscode: Multi-line Go control blocks are not correctly syntax highlighted HOT 4
- cmd: templ generate with watch can generate corrupted Go files, because of race condition with fsnotify WRITE events HOT 6
- Is there any way to generate raw attributes without any escaping? HOT 3
- generator: HTML Entites not rendering HOT 2
- LSP Server dont attach to Nvim HOT 2
- generator: Add support for templ type methods
- vscode: HTML attribute conditionals do not have proper syntax highlighting HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from templ.