I have gsp view files wherein tags are formatted for readability with whitespaces. I am expected to remove those so that the rendered html file is compact. So, is there a way in grails using plugin or any other means that I can tell grails to remove the whitespaces/newlines between tags and generate a compact view? I dont want to remove them from gsp file itself but only from the html file rendered by grails.
Asked
Active
Viewed 2,185 times
39
-
1Do you use at the top of your layout file, if you call one or at the top of your gsp file? – wannaKnowItAll Sep 11 '13 at 09:06
-
yeah... but how can it compact the rendered html.. isnt it a directive to browser... by render I am the tomcat/grails api building html from gsp..i want the html to not have any whitespace – Sumit Shrestha Sep 11 '13 at 09:40
-
This is a JSP thing, but I'd try it anyway. Put this at the top of your GSP: <%@ page trimDirectiveWhitespaces="true" %> – Gregg Sep 11 '13 at 16:10
-
@Gregg - does not appear to be implemented yet: http://jira.grails.org/browse/GRAILS-7623 (still marked as open) – nickdos Sep 16 '13 at 07:13
-
i'm not sure about is functional to your problem, do you know Jtidy?http://jtidy.sourceforge.net/index.html – ZaoTaoBao Sep 16 '13 at 09:39
-
Hello, Trying to clean up unanswered. Did you solve this? Maybe you can answer your own question. – Neoryder Oct 23 '15 at 12:44
-
@Sumit Though you have a widely accepted question, May you please add some gsp samples and screenshots etc to give an example of what you want. It will give me more hints around solving this problem. – Vinay Prajapati Aug 31 '16 at 04:44
-
You can use HtmlCompressor. Here is the answer: [Here is the answer](http://stackoverflow.com/questions/5488592/is-there-such-thing-as-a-jsp-minifier-or-open-source-html-minifier) – Harut Dec 06 '16 at 11:39
-
So you have to catch the HTML content (that is generated) before it goes to the browser. Then trim all white-spaces and new lines! – Ibrahim Mohamed Jun 03 '18 at 11:38
3 Answers
4
If the goal is to go easy on network transfer, enable the Spring Boot compression (gzip) in application.yml
server:
compression:
enabled: true
mime-types: application/json,application/xml,text/html,text/xml,text/plain,text/css,application/javascript

bassmartin
- 525
- 2
- 9
1
As @Gregg suggested,<%@ page trimDirectiveWhitespaces="true" %>
should help.
Also you can use decorators:

Robert
- 5,278
- 43
- 65
- 115

Taras Kohut
- 2,505
- 3
- 18
- 42
-2
How about using one of the yui-minify-resources or ui-performance plugins?
Here are the links: http://grails.org/plugin/yui-minify-resources http://grails.org/plugin/ui-performance

Nick De Greek
- 1,834
- 1
- 18
- 19
-
5Thanks. But, it seems that they are no more maintained by their developers. Also, They only work on css and js files. Any idea about html? – Sumit Shrestha Oct 24 '13 at 04:34