How can I create a link to a resource (image, .css file, etc.) from a .js file in a Grails application without hard-coding the application context?

In a .gsp file I can easily do this using the `r:img` or `r:resource` tags provided by the resources plugin. If the app isn't using this plugin, the `g:resource` tag can be used instead. However, neither of these plugins can be used from .js code.

My current solution (which I hate) is to put the .js code in a .gsp file, then use the aforementioned image tags, e.g.

```
<r:script>
  var imagePath = '<r:img file="foo/bar.png"/>';
<r:script>

```

Update
------

My question was how to link to a resource from a .js file, not from some JavaScript code within a `<script>` block in a GSP. In the latter case, I can use a GSP tag like `<r:img>` or `<r:resource>` or `<g:createLink>`, but GSP tags within .js files are ignored.