2

I have a few really huge json responses being sent to the client browser, and I'm trying to figure out how to compress them. I've tried using the ui-performance plugin as described in an answer to this question: How to compress output from a grails controller?

But it didn't work. My json file still is of the same size (~40MB) I've also tried using the yui-minify resources plugin, but to no avail. How else can I do this? Also, is it advisable to send such a huge json file to the browser? (A certain drop down selection on the front end lets the browser request a json response of this size each time the user selects an option)

Thanks!

Community
  • 1
  • 1
Shiva
  • 473
  • 1
  • 6
  • 21

3 Answers3

3

Grails 3.0 and later are based on Spring Boot which enables this functionality. You should look at the docs for your individual version but in Grails 3.2.2 you can add this to the 2nd section of your application.yml:

server:
    compression:
        enabled: true
        mime-types: application/json,application/xml,text/html,text/xml,text/plain
Gregor Petrin
  • 2,891
  • 1
  • 20
  • 24
  • What's the 2nd section of my application.yml supposed to be? You mean under "spring:"? – Machisuji Apr 24 '17 at 21:03
  • 1
    Grails uses --- to split the configuration into sections (in accordance with the YAML spec), but without naming those parts it is a bit confusing where to put a setting. By 2nd section I mean anywhere after the first --- and before the second --- delimiter. – Gregor Petrin Apr 25 '17 at 13:27
2

you can do it directly in tomcat http://viralpatel.net/blogs/enable-gzip-compression-in-tomcat/

Either do it directly in server.xml or inside the tomcat plugin

UPDATE

you can also try doing it manually, smth like:

def zipStream = new GZIPOutputStream( response.outputStream )  
zipStream.write( yourJsonString.getBytes() )  
zipStream.close()  
response.outputStream
injecteer
  • 20,038
  • 4
  • 45
  • 89
0

Give the Compress plugin a try

Steve
  • 1,457
  • 12
  • 25
  • Hey, no luck with that too. I added it(installed by including the code in BuildConfig.groovy, and tried it both with and without the code mentioned in the link you provided inside Config.groovy), but my application wouldn't load the json file itself. Threw me a 500 internal error once, and an ERR_CONNECTION_REFUSED the other time. – Shiva May 07 '14 at 06:43
  • >> Last updated by mischa 5 years ago that doesn't look good :/ – injecteer May 07 '14 at 10:08