Skip to content

Conversation

@noelwelsh
Copy link
Contributor

In development mode we don't want the web browser to cache assets, such as JS or CSS, that are under development. This PR implements this feature, which consists of a type of Route for managing assets. It:

  • sets up a directory watcher for a given directory, calculating hashes for each file in the directory and recalculating the hash on change.
  • implements pathTo by replaces file names with the file name + hash
  • serves files by removing the hash and serving the underlying file

A Handler is now a description, whilst the actual handling is carried
out by a RouteHandler. This allows a Handler to construct Resources when
it builds a RouteHandler. This will be used by the asset pipeline to
construct file watchers.

This requires the Runtime be factored into two parts, one available
before the http4s server is constructed, and one available after it is
constructed.
This will store the cache busting asset handler
- Rename `assets` to `asset`, following convention of singular, not
plural, package names.

- Extract `HashingFileWatcher` from `AssetRoute` and start adding tests

- Create type for hex encoded strings
- Add ScalaDoc

- Use a normal ADT for events, instead of trying to be clever with a
  union type
This is caused by our dependency on HexFormat, but Scala is moving
towards this as a minimum JDK dependency so it shouldn't cause us a problem.
Still work to do, but this fixes compilation errors.
Test is more robust and runs a bit faster
- Allow adjusting polling interval so that MacOS can increase the
interval

- Make test more robust by halting when all events have been observed,
instead of simple sampling in a duration.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants