Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compress html with PlayFramework

In order to improve the readability in the Scala forms I use indentation and new lines frequently. But when I verify the HTML when my play application is up and running I see a lot of white spaces and unnecessary line breaks. is there any why to compress this HTML out without "making my scala templates unreadable"?

Thanks

like image 829
adis Avatar asked Jul 09 '12 20:07

adis


3 Answers

As said in another answer there is nothing in the framework which permits to minify your HTML.

To do so you will have to use a front-end HTTP server like Nginx. You should have a look at strip module.

You should also ask yourself if such minification is really usefull. Gziping your answer will reduce its size. Adding minification on HTML (I have never seen that) seems premature optimization.

like image 104
kheraud Avatar answered Oct 26 '22 16:10

kheraud


It does exist HTML compression and is being used: https://code.google.com/p/htmlcompressor/

For play 2.x you can use the this filter

like image 43
Didac Montero Avatar answered Oct 26 '22 16:10

Didac Montero


As i read the play framework documentation it does not seem to support compressing of output html. It does support compressing of static assets (scroll down on this page).

Perhaps, if you run play behind a reverse proxy (e.g. via apache or nginx) i think you can have the proxy compress your html. (This might be worth another question.)

like image 1
df' Avatar answered Oct 26 '22 18:10

df'