播放框架自动javascript和CSS缩小器 [英] Play framework auto javascript and CSS minifier

查看:68
本文介绍了播放框架自动javascript和CSS缩小器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道一个很好的play插件,该插件会自动最小化javascript和CSS,以附加到生产Play服务器上吗?

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

我在这里看到的主要问题是从游戏端生成了javascript,插件将不得不检测动态生成的JS代码.主要是因为我将值直接写入javascript中,例如:

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');

推荐答案

我们之所以要对css/js/img进行最小化/压缩/合并是因为我们要节省网络带宽并加快应用程序性能,降低服务器负载并使用户更加满意.

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.

当您将这些常规变量放入javascript代码时,您将转移到另一种方式,即,使服务器变慢.因为每个请求将获得不同的javascript文件进行下载,并且用户将不再受益于本地缓存的js副本.出于相同的原因,使用greenscript或任何其他最小化工具进行压缩是没有意义的,因为每次您都需要重新压缩并合并,而不是直接从缓存中获取它.

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.

如果在某些情况下必须将groovy变量放入某些javascript代码中,则最好将它们与其他部分(应该占多数)分开.这样一来,您仍然可以使用greenscript或按来处理静态js文件,而将动态部分保留在视图内.

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.

这篇关于播放框架自动javascript和CSS缩小器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆