Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Page resource handling for caribou (although it's just a ring handler and can work with any ring application).


porcupine is a library to assist with the management of page resources (javascript files, stylesheets, favicons). It allows your code and templates to declare that they require certain resources, safe in the knowledge that:

  • They will be included in the order in which they are added
  • No resource will be included twice

Declaring resources

To declare that you need resources, you can either do it from your code, using the add-resource function, or within a template using the add-resource helper:

(add-resource <type> <path> [opts])


{{add-resource <type> <path> [opts]}}

At the present time, :javascript, :stylesheet and :icon types are supported. The path can be relative or absolute, and will be inserted into the template exactly as you provide it. You can also specify an optional options map. At present the only option available is :location, which you can provide any keyword you like. If you provide :header or :footer, you can use the template helpers header-resources and footer-resources to render them where you want them in the template.

Rendering resources

In your template, you need to indicate where you want the resources to be injected after rendering is complete. You can use a number of helpers to do this, or you can easily build your own helper if you need custom behaviour. The provided helpers are all-resources, javascript-resources, stylesheet-resources, footer-resources, and header-resources. They do pretty much exactly what you might think.

NOTE: You will need to use the triple-curly-brace format in your template in order for the unescaped resource tags to be injected correctly.

For example:

    {{add-resource :javascript "/foo/bar.js"}}
    {{add-resource :javascript "/foo/quux.js"}}
    {{add-resource :javascript "/foo/baz.js"}}

will result in this:

    <script type="text/javascript" src="/foo/bar.js"></script>
    <script type="text/javascript" src="/foo/quux.js"></script>
    <script type="text/javascript" src="/foo/baz.js"></script>

Note that the positions of the calls to add-resource are not relevant, and that the resources are injected at the place where {{{all-resources}}} appears.


Copyright © 2013 FIXME

Distributed under the Eclipse Public License, the same as Clojure.


Intelligently handle page resources when rendering pages in a ring/caribou application.



No releases published
You can’t perform that action at this time.