Play framework auto javascript and CSS minifier

安稳与你 提交于 2019-12-22 18:15:14

问题


Does anyone know a good play plugin that automatically minifies javascript and css to attach to a production play server?

I've found this one, but I guess there are more out there:

https://github.com/greenlaw110/play-greenscript

The main problem I see here is that the having javascript being generated from the play side, the plugin would have to detect JS code that gets generated on the fly. Mainly because I'm writing values directly into the javascript like:

function foo${handlerID}(someVar){
var x = ${some_val};

(...)
}

var t = foo${handlerID}('bar');

回答1:


The reason we do minimizing/compressing/merging for css/js/img is because we want to save the network bandwidth and accelerate application performance, lower the server's load and make the user be more happy.

When you are putting those groovy variables into your javascript code you are shifting to the other way, i.e. making the server slowing down. Because each request will get a different javascript file to be downloaded, and the user will be no longer benefit from the local cached js copies. For the same reason using greenscript or any other minimizing tool to compress it is meaningless, because each time your need to compress and merge again instead of get it directly from cache.

If there are cases that you HAVE TO put the groovy variables into some javascript code, you'd better separate them from other parts (which should reasonably be most the majority). By doing that you could still using greenscript or press to process your static js files and leave the dynamic parts stay inside your view.




回答2:


Check out the press module. As long as the generated Javascript and css are in their separate own respective files you should be able to minify them automatically.



来源:https://stackoverflow.com/questions/8342743/play-framework-auto-javascript-and-css-minifier

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