This workspace provides a small template demonstrating three client-side techniques for dynamic updates:
- Polling (fetch) — works with static servers
- Server‑Sent Events (SSE) — server -> browser push over HTTP
- WebSocket — bidirectional low-latency channel
Files added:
index.html— client UI to choose mode and start/stop updatesserver_sse.js— Express-based SSE example (serves static files)ws_server.js— WebSocket server example usingwspackage.json— convenience scripts
Quick start
- Install Node deps (for SSE and WS servers):
npm install- Run the SSE server (serves
index.htmland/events):
npm run start-sse
# open http://localhost:3000/- Run the WebSocket server (serve
index.htmlseparately):
npm run start-ws
# in another terminal (serve static files):
npm run start-static
# open http://localhost:8000/- Or just run a static server and use polling:
npm run start-static
# open http://localhost:8000/Notes
- For production, secure WebSocket and SSE endpoints (TLS) and handle reconnection/backoff.
- The template app uses
simple.txtfor polling; replace with your API or endpoint.
Since GitHub Pages only serves static files, you can use the polling template which fetches from a JSON file:
- Open
github-pages.htmlin your browser (or serve it locally for testing). - The page polls
data.jsonevery 2 seconds (adjustable). - To trigger updates, either:
- Manually edit
data.jsonand push to your repo. - Let the GitHub Actions workflow auto-update it every 5 minutes (see below).
- Manually edit
Setup automatic updates with GitHub Actions:
- The workflow
.github/workflows/update-data.ymlruns every 5 minutes and bumpsdata.json. - It will only commit if data actually changed (to avoid noise).
- To modify the schedule, edit the
cronline in the workflow file.
To deploy on GitHub Pages:
git add github-pages.html data.json .github/workflows/update-data.yml
git commit -m "Add GitHub Pages live update template"
git push origin mainThen enable Pages under repo Settings → Pages → deploy from main branch.
Use the update-simple.yml workflow to update simple.txt from GitHub without pushing code:
- Go to your repo on GitHub → Actions tab
- Select "Update simple.txt" workflow
- Click "Run workflow" (dropdown on the right)
- Optionally enter a custom message in the input field
- Click "Run workflow" again to confirm
- The workflow commits and pushes the change automatically
The page polling simple.txt (using index.html or github-pages.html) will fetch the updated content on the next interval.
Credits
- Template created and documented by the project owner with assistance from GitHub Copilot.
If you'd prefer a different credit line or additional author information, let me know and I can update this.