How to compress html with PlayFramework

走远了吗. 提交于 2019-12-22 05:45:26

问题


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


回答1:


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.




回答2:


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




回答3:


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



来源:https://stackoverflow.com/questions/11402624/how-to-compress-html-with-playframework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!