britva britva - 1 month ago 12x
Scala Question

Static resource reload with akka-http

In short: is it possible to reload static resources using akka-http?

A bit more:

  • I have Scala project.

  • I'm using
    object to launch my


  • I'm using
    to locate my resource

What I would like to have is to hot-swap my static resources during development.
For example, I have
, which I change and I want to see changes after I refresh my browser without restarting my server. What is the best practise of doing such thing?

I know that
allows that, but don't want to base my project on
only because of that.


Two options:

  1. Easiest: use the getFromDirectory directive instead when running locally and point it to the path where your files you want to 'hotload' are, it serves them directly from the file system, so every time you change a file and load it through Akka HTTP it will be the latest version.
  2. getFromResourceDirectory loads files from the classpath, the resources are available because SBT copies them into the class directory under target every time you build (copyResources). You could configure sbt using unmanagedClasspath to make it include the static resource directory in the classpath. If you want to package the resources in the artifact when running package however this would require some more sbt-trixery (if you just put src/resources in unmanagedClasspath it will depend on classpath ordering if the copied ones or the modified ones are used).