[hunchentoot-devel] How to use/generate/access javascript/css?

Toby tobia.conforto at linux.it
Mon Oct 23 14:50:31 UTC 2006


Vamsee Kanakala wrote:
> Sorry for the newbie questions, I'm curious as to how people working 
> with tbnl/hunchentoot create/maintain their javascript and css files.

I mostly use static css and js files.  I put them in the root directory
of my website and then create a handler for those specific extensions*.
If I have more than a few I simply put them into css/ and js/ folders.

To include them, just generate the relevant HTML code:

(:html 
  (:head 
    (:link :href "myfile.css" :rel "stylesheet" :type "text/css")
    (:script :src "myfile.js" :type "text/javascript" nil)
    ...

The last nil creates <script></script> which works better than <script/>

If I need to generate dynamic css or js snippets, I just put them into
the HTML page: <style> tags in head and <script> tags in head or body.


HTH
Toby


*: (create-extension-dispatcher-and-handler '("html" "css" "js"))  
where:
(defun create-extension-dispatcher-and-handler (extensions)
  (create-regex-dispatcher 
    (format nil "^/[^/]+\\.(~{~A~^|~})$" extensions)
    (lambda () (handle-static-file (string-left-trim "/" (script-name))))))



More information about the Tbnl-devel mailing list