3 hours ago · Tech · 0 comments

In my previous post, I explained how I use the FSEvents API to detect changed files on macOS. It’s part of my livereload mechanism for working on this site. I make a change to a source file, that triggers a rebuild of the site, and then the development site automatically refreshes in my web browser. I’m trying to build this all myself, with no third-party dependencies. Once I’ve detected a changed file and rebuilt the site, how do I automatically refresh my open browser windows? In this post, I’ll explain how I use HTTP long polling to tell pages when it’s time to reload. Table of contents HTTP long pollingFaster isn’t always betterSending reload events from a Python web serverWaiting for a long-polling server in JavaScript Making this code more robustUsing threading to support multiple connectionsAvoiding default fetch() timeouts Rejected approaches The result HTTP long polling Faster isn’t always better In most HTTP servers I’ve built, when the server sends a response to a client, I…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.