How to compress html with PlayFramework

2019-04-28 23:32发布

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

3条回答
该账号已被封号
2楼-- · 2019-04-29 00:13

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.)

查看更多
我想做一个坏孩纸
3楼-- · 2019-04-29 00:29

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

查看更多
贪生不怕死
4楼-- · 2019-04-29 00:31

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.

查看更多
登录 后发表回答