4

My Grails 1.3.7 controller is generating some JSON & I would like to send it to the client in compressed (zipped) form, as the amount of JSON can be 2+MB uncompressed. The resources plugin I found seems to compress static resources only. Is there a way to compress dynamic controller output as well?

Gene Golovchinsky
  • 6,101
  • 7
  • 53
  • 81
  • Could [Ui-Performance](http://grails.org/plugin/ui-performance) plugin help? I am not sure about the usage but one of the feature of the plugin is to gzip dynamic text content like JSON. – dmahapatro Jun 26 '13 at 01:10

2 Answers2

0

I guess you would need the below configuration in Config.groovy if Ui-Performance plugin is used:

uiperformance.html.includeContentTypes = ['text/json','application/json']

Also have a look a CompressingFilter API which is used to compress HttpServletResponse. If curious, you can also peep at the source as to how the web descriptor is manipulated to use the compressor.

dmahapatro
  • 49,365
  • 7
  • 88
  • 117
0

If you're serving your grails application from behind a web-server like apache or nginx, you can configure the compression in the front-end rather easily.

See mod_deflate for apache and HttpGzipModule for nginx.

If you would rather do the compression work inside your jar, you can either create a ServletFilter and do the compression yourself as mentioned in this SO question or use something like the UI-Performance plugin as mentioned by dmahapatro.

Community
  • 1
  • 1
codelark
  • 12,254
  • 1
  • 45
  • 49