2
votes

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!

3

3 Answers

3
votes

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
2
votes

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
0
votes