Liking cljdoc? Tell your friends :D

Static Resources (Clojure Only)

Static resources can be served using reitit.ring/create-resource-handler. It takes optionally an options map and returns a ring handler to serve files from Classpath.

There are two options to serve the files.

Internal routes

This is good option if static files can be from non-conflicting paths, e.g. "/assets/*".

(require '[reitit.ring :as ring])

    [["/ping" (constantly {:status 200, :body "pong"})]
     ["/assets/*" (ring/create-resource-handler)]])

To serve static files with conflicting routes, e.g. "/*", one needs to disable the conflict resolution:

(require '[reitit.ring :as ring])

    [["/ping" (constantly {:status 200, :body "pong"})]
     ["/*" (ring/create-resource-handler)]]
    {:conflicts (constantly nil)})

External routes

A better way to serve files from conflicting paths, e.g. "/*", is to serve them from the default-handler. One can compose multiple default locations using ring-handler. This way, they are only served if none of the actual routes have matched.

    ["/ping" (constantly {:status 200, :body "pong"})])
    (ring/create-resource-handler {:path "/"})


reitit.ring/create-resource-handler takes optionally an options map to configure how the files are being served.

:parameteroptional name of the wildcard parameter, defaults to unnamed keyword :
:rootoptional resource root, defaults to \"public\"
:pathoptional path to mount the handler to. Works only if mounted outside of a router.
:loaderoptional class loader to resolve the resources
:index-filesoptional vector of index-files to look in a resource directory, defaults to [\"index.html\"]
:not-found-handleroptional handler function to use if the requested resource is missing (404 Not Found)


  • support for things like :cache, :etag, :last-modified?, and :gzip
  • support for ClojureScript
  • serve from file-system

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close