Now, how does reloading a web server work? I knew `tower-livereload` injected code, but a bit of further digging led to #link("https://emnudge.dev/notes/live-reload/"), which alongside the HTTP spec and the Rust Book web server tutorial, informed the basis of my implementation. As it turns out, we control the web server code, and the web server tells the browser what to render, so we can easily inject any (JavaScript) code we need to run on that front---just insert it right before responding to the client. Conceptually, that code just says "any time I get notified, reload the page." We wait for notifications via JavaScript's #link("https://developer.mozilla.org/en-US/docs/Web/API/EventSource")[`EventSource`], which opens a connection to a server and gets pinged every time that server sends a message back. The specific spec says something along the following: when a server receives a request from an `EventSource`, it should respond `OK` with the mime-type `text/event-stream`. I sent the rust byte string:
0 commit comments