How are Javascript resources best integrated into a ring application?
Specifically:
Are there any best practices for javascript with ring applications? One possible answer would be to develop the client and server sides completely separately, to essentially separate everything into two separate projects, but I'm not completely happy with that idea.
(I'm also aware of clojurescript, though I'm thinking mainly of javscript code that's been written as javascript.)
Ring has support to serve files directly from a folder (ring.middleware.file
or ring.middleware.static
which is what I would use) or from a resource in the jar/war. Your best bet is to use these mechanisms to serve your static (javascript/images) content. If you have the freedom to do this, I will put in a route similar to this one to serve all HTTP requests at /static/
from such a folder:
(def *route*
(ring/wrap-static "c:/statics/" ["/static/"]))
Once you know how to handle a request for a static resource (like a javascript resource) it's the same as with anything else like PHP or ASP.
Another alternative is to define your resource routes as per normal, and then in the "catch-all" (normally something like this (ring/GET * request (handle-static-request request))
route, handle any remaining unserviced request with a static request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With