Wednesday, August 26, 2009

Using JSMGR to Compress a Single Script

JSMGR as currently designed handles the compression and combination of several scripts very well. But what if you just want to access a single script?

Currently in order to access a single script you'll have to use the following URL:

http://<host>/js?s=path/to/js-file.js

It is just a tag bit more inconvenient than

http://<host>/js/path/to/js-file.js

Fortunately it is simple for us to handle pathinfos:

;; the javascript! loader will depend on a having a paticular setting
(define (js/css! (scripts ($query* "s")) #:base (base (current-directory)) #:compress! (compress! yui-compress!))
(define (scripts-helper)
(open-js/css-files/base
(if (not (null? ($pathinfo)))
(cons (string-join (filter (lambda (segment)
(not (string=? segment "")))
($pathinfo))
"/")
scripts)
scripts)
base
compress!))

(raise
(http-client-response->response
(make-http-client-response "1.1"
200
"OK"
'(("Content-Type" . "text/javascript"))
(scripts-helper))
(lambda (x) x))))

Now if we want to pass a single script "normally" - we can do that.

This single script support is currently only available in the shp adapter, not the servlet adapter.

No comments:

Post a Comment