2

I have a JS file that is included in my GSP template as follows:

<r:script type="text/javascript">
    <g:render template="/javascript/common"/>
</r:script>

The /javascript/common outputs some dynamic JS e.g. pre-populates lists client side. It's dynamic per server restart i.e. it doesn't need to be generated per request, but rather more commonly on redeployment.

I'm wondering how I can process it as a resource using the resource plugin and get the ability to minify it and compress it etc.

There may be times where it would need to be refreshed. Is it possible to support refreshing it in a similar fashion to other resources i.e. when the underlying file is modified the plugin reloads it.

thanks ...

1

1 Answer 1

1

The best way to ensure it cooperates with the resource plugin would be to create a custom ResourceMapper

Oversimplified version:

  1. Create a file with ResourceMapper.groovy as the file suffix, in the grails-app/resourceMappers folder.
  2. Decorate the class using def phase = MapperPhase.GENERATION
  3. Implement def map(resource, config) {} to generate your resource when requested.

Your custom mapper will run once per deployment, then use the static generated file. All of the minify/compress, you're using will, of course, run after the GENERATION phase.

UPDATE: It does look like the Gsp Resources plugin @Ruben suggested would do what you're looking for. You can see the source for its custom mapper.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.