预编译javascript [英] precompile javascript

查看:77
本文介绍了预编译javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力提高使用

javascript的嵌入式应用的性能。我们的javascript函数很长,并且(为了便于

维护)非常详细。


我们已经做了一些事情,比如内联javascript和css以最小化负载

次。分析表明提高

性能的下一个最佳方法是减少javascript解析的时间。


我正在寻找可以预先设置的PHP脚本处理javascript到

将所有长变量名称减少为一个或两个字母,取出额外的

空格,注释等,否则将javascript减少到barest

最低运行时间。


有什么建议吗?


- 颜色

I am trying to improve the performance of an embedded app that uses
javascript. Our javascript functions are quite long, and (for ease of
maintenance) quite verbose.

We already do things like inline the javascript and css to minimize load
times. Profiling indicates that the next best way to improve
performance is to reduce the time for javascript parsing.

I am looking for a php script that could pre-process the javascript to
reduce all long variable names to one or two letters, take out extra
spaces, comments, etc and otherwise reduce the javascript to the barest
minimum necessary to run.

Any suggestions?

--Yan

推荐答案

CptDondoaécrit:
CptDondo a écrit :

我正在努力提高使用
$ b的嵌入式应用程序的性能$ b javascript。我们的javascript函数很长,并且(为了便于

维护)非常详细。


我们已经做了一些事情,比如内联javascript和css以最小化负载

次。分析表明,提高性能的另一个最佳方法是减少javascript解析的时间。
I am trying to improve the performance of an embedded app that uses
javascript. Our javascript functions are quite long, and (for ease of
maintenance) quite verbose.

We already do things like inline the javascript and css to minimize load
times. Profiling indicates that the next best way to improve
performance is to reduce the time for javascript parsing.



Bof!很少这是一个痛苦

(特别是与图像的重量相比)

Bof! So little that it is a misery
(especially compared with the weight of images)


我正在寻找一个可以预先设置的PHP脚本 - 处理javascript到

将所有长变量名称减少为一个或两个字母,取出额外的

空格,注释等,否则将javascript减少到barest

运行所需的最低限度。
I am looking for a php script that could pre-process the javascript to
reduce all long variable names to one or two letters, take out extra
spaces, comments, etc and otherwise reduce the javascript to the barest
minimum necessary to run.

http://www.crockford.com/ javascript / jsmin.html


如果你担心脚本需要的字符数是多少,那么你是什么意思需要压缩和缓存。你可以缩小你喜欢的所有

,但这两种技术合在一起会将数据减少到10%(无论函数名称的长度等)和

那么只会在很多秒内提供ONCE。在apache和php下,两者都是

标准,完成工作!我确实兴奋地为一些

巨大的javascripts(scriptaculous all in one file,moofx,bahaviours

等......总重量为250k,降至约20k)

内联代码可能会适得其反,因为它会使用少量的b
请求,但代价是无法压缩和缓存

js文件,如果网页不能(如果它们是php的结果,

无法缓存)。

if you are worrying about the number of characters that a script takes
up, then what you need is compression and caching. You can minify all
you like, but these two techniques taken together will reduce the data
size down to 10% (regardless of lengths of names of functions etc) and
then that will only be served ONCE per however many second. Both are
standard under apache and php, job done! I did excatly that for some
HUGE javascripts (scriptaculous all in one file, moofx, bahaviours
etc... a total weight of 250k down to about 20k)
Inlining your code might be counter-productive as it will use one less
request but at the expense of not being able to compress and cache the
js file, if the web pages cant be (if they are the result of php which
cannot be cached).


shimmyshack写道:
shimmyshack wrote:

如果你担心脚本占用的字符数是多少b $ b up,那么你需要的是压缩和缓存。你可以缩小你喜欢的所有

,但这两种技术合在一起会将数据减少到10%(无论函数名称的长度等)和

那么只会在很多秒内提供ONCE。在apache和php下,两者都是

标准,完成工作!我确实兴奋地为一些

巨大的javascripts(scriptaculous all in one file,moofx,bahaviours

等......总重量为250k,降至约20k)

内联代码可能会适得其反,因为它会使用少量的b
请求,但代价是无法压缩和缓存

js文件,如果网页不能(如果它们是php的结果,

无法缓存)。
if you are worrying about the number of characters that a script takes
up, then what you need is compression and caching. You can minify all
you like, but these two techniques taken together will reduce the data
size down to 10% (regardless of lengths of names of functions etc) and
then that will only be served ONCE per however many second. Both are
standard under apache and php, job done! I did excatly that for some
HUGE javascripts (scriptaculous all in one file, moofx, bahaviours
etc... a total weight of 250k down to about 20k)
Inlining your code might be counter-productive as it will use one less
request but at the expense of not being able to compress and cache the
js file, if the web pages cant be (if they are the result of php which
cannot be cached).



其实我是试图最小化解析文件所需的时间。

内联CSS和js将加载时间从38秒减少到16 ....从

无法使用。


所以现在我们想要在这里再挤出几秒钟,然后在那里花费
。如果我能通过缩小来做到这一点,那很好。如果没有,我会尝试

别的东西。


系统都是通过PHP驱动的;在任何地方都没有缓存。

文件系统是只读的,而/ tmp文件系统是基于ram的,所以我想要

来最小化它的使用。


--Yan

Actually I am trying to minimize the time it takes to parse the file.
Inlining CSS and js reduced load times from 38 seconds to 16.... From
unusable to bearable.

So now we''re looking to squeeze a few more seconds out of it here and
there. If I can do that by minifying, great. If not, I''ll try
something else.

The system is all driven via PHP; there is no caching anywhere. The
file system is read-only and the /tmp filesystem is ram-based, so I want
to minimize its use.

--Yan


这篇关于预编译javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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