Fork me on GitHub

Since the def would be evaluated whenever the namespace was loaded, I’d be very wary of that approach… If you don’t want to have a genuine "application start" function that is called at startup, you could use delay to ensure that the file is only read when you need the contents of if:

(def edn-contents (delay (slurp ( "path/to/file.edn"))))

(defn handler [req]
  {:status 200
   :body @edn-contents})
This still ensures the file is only read once, but now you can load the namespace without actually reading the file.


The problem with a raw def is that if you AOT compile your code (to produce an uberjar etc), the file would be read during compilation.


thank you for detailed explanation!