Flutter-Bounty-Hunters / static_shock

A static site generator for Dart.
MIT License
59 stars 5 forks source link

shock serve now auto-refreshes HTML pages when any source file changes, also port is now configurable (Resolves #41) #61

Closed matthew-carroll closed 6 months ago

matthew-carroll commented 6 months ago

shock serve now auto-refreshes HTML pages when any source file changes, also port is now configurable (Resolves #41)

During shock serve, the /source directory is watched. Any reported file system change triggers a full website rebuild.

The shock serve dev server now intercepts all HTML files that it serves and injects some JavaScript that connects a websocket with the dev server. Every time shock serve rebuilds the website, it notifies all registered websockets that a change has occurred, and the injected JavaScript refreshes the whole page.

Users can now specify the server port with the --port flag. Additionally, if the desired port is in use, the server will try to find a nearby open port. Port searching can be disabled with the --no-find-open-port flag.

In the future, it might be a good idea to have the server send the updated HTML for the page, rather than doing a full refresh, so that some page state might be preserved across the reload.

In the future, it might be good to only refresh a page when that particular page and its dependencies change. But, it's unclear how to calculate the dependencies. An HTML page might have any number of dependencies on CSS files, JS files, images, etc. Also, some of these dependencies might not exist until runtime, due to JavaScript creating the dependencies.

In the future, it would be good to improve the website build time. It's currently sitting at a few seconds to build a very simple website. This is too long for effective auto-refresh on larger and more complicated websites.