diff --git a/README.md b/README.md index be146d2..36a176f 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,41 @@ But it can be customized to include other directories: your-handler ["src" "resources" "checkouts/foo/src"])) ``` +### Caveats + +Do note this library will only refresh the browser and nothing else. This means updates on the code will trigger a browser refresh, but the code itself won't be reloaded. + +This is good when the assets you are modifying reside in `resources/` such as html, css and js files. However, sometimes you might reach for tools such as [hiccup](https://github.com/weavejester/hiccup) for HTML templating. Under these scenarios, `ring-refresh` needs something else to reload the code for it. + +The following is an example using `ring.middleware.reload` to reload the code when you modify the `hiccup` template. You can alternatively reload with the REPL. + +```clojure +(ns test.core + (:require [ring.adapter.jetty :refer [run-jetty]] + [ring.middleware.reload :refer [wrap-reload]] + [ring.middleware.refresh :refer [wrap-refresh]] + [hiccup.page :refer [html5]])) + +(defn home-page [] + (html5 + [:head + [:title "Ring Refresh Example"]] + [:body + [:p "This page will auto-refresh when you change the source code."] + [:p "Try changing something and saving the file, and you'll see the update automatically."]])) + +(defn handler [request] + {:status 200 + :headers {"Content-Type" "text/html"} + :body (home-page)}) + +(def app + (-> handler + wrap-refresh)) + +(defn -main [] + (run-jetty (wrap-reload #'app) {:port 3000})) +``` ## License