Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
The typical solution is to inject some JavaScript so that the client can be notified of changes. Nowadays, you'd typically use Web Sockets for this so that the server can actively notify the client...
#1: Initial revision
The typical solution is to inject some JavaScript so that the client can be notified of changes. Nowadays, you'd typically use Web Sockets for this so that the server can actively notify the client when changes are made. This leads to the quickest reaction to changes of the source files. The other alternative is to have the client poll for changes. Once you have a mechanism for the client-side to notice changes from the server, there are a variety of ways of actually implementing those changes. By far the simplest thing to do, which is probably completely adequate for your purposes, is to just have the page to a reload with `window.location.reload()` in JavaScript. That means all that needs to be sent over a Web Socket or received via polling is a notification that *something* has changed. At the other end of the spectrum is stuff like [React's Fast Refresh](https://nextjs.org/docs/architecture/fast-refresh) which can make incremental changes and maintain client-side (React) state. Obviously, this is in the context of a React web app. Intermediate (and used by Fast Refresh) is [webpack's Hot Module Replacement](https://webpack.js.org/concepts/hot-module-replacement/) which allows replacing JavaScript modules on the fly, but doesn't, by itself, maintain state. It probably wouldn't be hard to implement something that works a bit differently but still serves your purposes well. At the most basic level, you could just send the full generated HTML of the actual content and then just do `mainContainer.innerHTML = receivedHTML`. This is tantamount to refreshing the page but will probably look more seamless. If you wanted to go further, you could diff the generated HTML and then send (logical) updates instead of the full generated output. This would take much more development effort to implement (from scratch at least) and likely would be a marginal improvement in responsiveness.
