Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

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

60%
+1 −0
Q&A Python http.server how can I programatically refresh the browser page?

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...

posted 9mo ago by Derek Elkins‭

Answer
#1: Initial revision by user avatar Derek Elkins‭ · 2025-12-17T18:06:02Z (9 months ago)
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.