Main difference is compojure.route/resources
only serve resources from a specific path:
(let [root (:root options "public")]
(resource-response (str root "/" resource-path))
But ring.middleware.resource/wrap-resource
provides a fail-back mechanism on a handler if no resource is found:
(or (response/resource-response path {:root root-path})
(handler request))
As you see from the resource-response
function both alternatives use:
(defn resource-response
"Returns a Ring response to serve a packaged resource, or nil if the
resource does not exist.
Options:
:root - take the resource relative to this root"
It returns nil
if the requested resource is not found.
So the wrap-resource
alternative is more suitable to be chained if you already have routes in place, as in:
(defroutes routes
(GET "/" [] "<h1>Hello World</h1>")
(route/not-found "<h1>Page not found</h1>"))
(def app (-> routes
(wrap-resource "public/resources"))
And the compojure.route/resources
you can use for route composition, as in:
(defroutes resources-routes
(route/resources "/"))
(defroutes routes
(GET "/" [] "<h1>Hello World</h1>")
(route/not-found "<h1>Page not found</h1>"))
(def app
(compojure.core/routes
resources-routes
routes))