Thanks Peter for sharing this.

Great workflow!

Cheers,
Hubert.

On Jul 26, 2011, at 6:59 AM, Peter Taoussanis wrote:

>> I would also love to know how you set this up in a little more detail. It 
>> really sounds like an excellent approach…
> 
> Sure: it's not complicated! I'm writing this in a hurry though- so
> hope it's still clear.
> 
> Basically I just define a memoized "dynamic scripts" function that
> returns a map with a text/javascript Ring response, along with a hash
> of that response.
> 
> So something like (def dynamic-scripts (memoize (function []
> {:response foobar :hash (make-hash foobar)}))
> 
> Then I've got a Compojure route configured to serve requests like so:
> (GET "/dynamic-stuff/:hash/scripts.js" {} (:response (dynamic-
> scripts)))
> 
> This'll just send back the memoized script response anytime a request
> is made for /dynamic-stuff/whatever/scripts.js
> 
> The /whatever/ is important since it let's me automatically include
> the current hash in any script tags in the HTML with URI (str "/
> dynamic-stuff/" (:hash (dynamic-scripts)) "/scripts.js").
> 
> 
> Now all I need to do when I want to tweak the scripts is reevaluate
> the namespace they're in and it'll re-hash, meaning that all future
> requests for scripts.js go to the new resource - avoiding any possible
> caching issues.
> 
> 
> What I've described so far doesn't necessitate anything ClojureScript.
> But with ClojureScript, the dynamic-scripts function can be easily
> modified to produce it's response by compiling ClojureScript source.
> This is awesome since it means I can keep everything in one
> environment, and compilation happens automatically any time there is a
> change to the underlying source. The scripts.js is always optimized,
> always up-to-date, and always hashed to avoid caching problems.
> 
> When I want to test a change to the scripts, I just reevaluate the ns
> then refresh my browser and the changes are live. If there's a major
> compile-time bug in the scripts, it'll get caught before any changes
> take affect.
> 
> BTW if the devs are listening, it'd be nice if cljsc/build could one
> day also support input/output directly via strings :) That'd make all
> this absolutely trivial(er).
> 
> --
> Peter
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to