简体   繁体   English

使用Flash,Javascript和JSP优化我的Web应用程序

[英]Optimizing my web application using Flash, Javascript and JSP

I have a web app that I am trying to speed up. 我有一个网络应用程序,我正在努力加快。 It looks like this: 它看起来像这样:

+------+
|      |
|      |
+------+

+------+
|      |
|      |
+------+

+------+
|      |
|      |
+------+

Each box is an iFrame containing a Flash SWF and some javascript. 每个框都是一个包含Flash SWF和一些javascript的iFrame。 The SWF downloads a thirdparty SWF that is used to display information. SWF下载用于显示信息的第三方SWF。 I have found that the load time for the webapp is: 我发现webapp的加载时间是:

LoadTime = (4 seconds) * numberOfBoxes + (3 seconds) 

When I just imbed the 3rd party swf directly (without our swf or the javascript) the load time is: 当我直接嵌入第三方swf(没有我们的swf或javascript)时,加载时间是:

LoadTime = (1 second) * numberOfBoxes + (2.5 seconds)

I am trying to find where the extra 3 seconds is being used so that I can speed up our webapp. 我试图找到额外3秒的使用位置,以便我可以加快我们的webapp。 I think that the candidates are: 我认为候选人是:

  • Serverside processing (jsp) 服务器端处理(jsp)
  • Download 下载
  • Javascript 使用Javascript
  • Flash
  • Other? 其他?

Download 下载

Below is an image of the downloads taken from firebug. 下面是从firebug下载的下载图像。 I have replaced the file names with what their type is. 我已经用它们的类型替换了文件名。 None of the downloads are taking especially long after the first time . 第一次下载 ,所有下载都没有。

One place of interest however is marked in red. 然而,一个感兴趣的地方用红色标记。 The red area is a 3 second gap between when My SWF is loaded and when two gif files are loaded followed by the Third Party SWF . 加载“ My SWF和加载两个gif文件,然后是Third Party SWF之间的红色区域是3秒的间隙。 I think this pause is caused by processing on the client (is this true?). 我认为这个暂停是由客户端上的处理引起的(这是真的吗?)。

在此输入图像描述

Note: The red bars in the graph are not part of the diagram. 注意:图表中的红色条不是图表的一部分。 I added them to highlight the gap where nothing is occurring on the .net panel . 我添加它们以突出显示.net面板上没有任何内容发生的间隙

I think that I can conclude from this that I have a client side processing issue which implies either Flash or Javascript. 我认为我可以从中得出结论,我有一个客户端处理问题,暗示Flash或Javascript。 Question 1: Is this correct? 问题1:这是正确的吗?

Edit: I added up the total non-concurrent download time: 编辑:我添加了非并发下载总时间:

  • When there is 1 iframes the download time is 1.87 seconds 当有1个iframe时 ,下载时间为1.87秒
  • When there is 2 iframes the download time is 2.29 seconds 当有2个iframe时 ,下载时间为2.29秒
  • When there is 5 iframes the download time is 8.57 seconds 当有5个iframe时 ,下载时间为8.57秒
  • When there is 10 iframes the download time is 10.62 seconds 当有10个iframe时 ,下载时间为10.62秒
  • When there is 21 iframes the download time is 17.20 seconds 当有21个iframe时 ,下载时间为17.20秒

Javascript 使用Javascript

I used the profiler in firebug to profile the javascript. 我在firebug中使用了profiler来分析javascript。 Here are the results when there are four components on the page: 以下是页面上有四个组件的结果:

在此输入图像描述

This means that the javascript is running for about .25 second/chart. 这意味着javascript运行大约.25秒/图表。 This seems reasonable to me. 这对我来说似乎很合理。

Question 2: Am I reading these results correctly? 问题2:我是否正确阅读了这些结果?

This leaves about 3.5 seconds/chart of processing for something else. 这留下了大约3.5秒/处理其他内容的图表。

Flash

I inserted some trace statements in the AS3 code. 我在AS3代码中插入了一些trace语句。 We are listening to an event called something like "done loading". 我们正在听一个名为“完成加载”的事件。 I put a trace in the first initialize method and in the "done loading" method. 我在第一个初始化方法和“完成加载”方法中添加了一个跟踪。 The flash is only eating up .2 second/chart between those two trace statements. 闪存仅在这两个跟踪语句之间消耗.2秒/图表。

Question 3: Is there a better way to to profile the flash? 问题3:有没有更好的方法来配置闪存? Could it be the flash loading or something like that that is eating up the extra time? 可能是闪存加载或类似的东西正在耗费额外的时间?

Other 其他

I am not sure if there are other things other than: 我不确定是否还有其他事情:

  • Serverside processing (jsp) 服务器端处理(jsp)
  • Download 下载
  • Javascript 使用Javascript
  • Flash

Question 4: Is there something that I am missing that could be eating up time? 问题4:我有什么遗失可能会占用时间吗?

Next Steps 下一步

I am not sure what my next step should be. 我不确定我的下一步应该是什么。 I know that something is taking about 1.5 - 3 seconds/chart but I cannot figure out what it is. 我知道有些事情需要大约1.5 - 3秒/图表,但我无法弄清楚它是什么。 I suspect that it is something related to my swf. 我怀疑这与我的瑞士法郎有关。

Question 5: How should I find that missing time? 问题5:我该如何找到错过的时间?

Update : Time Summary 更新 :时间摘要

I have graphed all of the times for each thing that could be taking time. 对于每件可能需要时间的事情,我都画了所有的时间。

  • The X-axis is the number of charts that are being used. X轴是正在使用的图表数量。
  • The Y-axis is the about of time loading all of the charts takes. Y轴是加载所有图表所需的时间。

The last graph is possibly the most important graph. 最后一张图可能是最重要的图。 The blue dots is the amount of total loading time (measured using a stop watch). 蓝点是总加载时间(使用秒表测量)。 The red dots are the amount of time that I have accounted for (Javascript, download time and flash time). 红点是我考虑的时间量(Javascript,下载时间和闪光时间)。

在此输入图像描述

Update : Browser Wars 更新 :浏览器大战

I am targeting IE and Firefox (although it is a nice bonus if other browsers work). 我的目标是IE和Firefox(如果其他浏览器工作,这是一个很好的奖励)。 All of the results presented so far are with Firefox with firebug running. 到目前为止,所有结果都是火狐运行的Firefox。 Just for fun I thought I would try in other browsers. 只是为了好玩,我想我会在其他浏览器中尝试。 I don't think that this brings me closer to a solution but interesting to see how much IE sucks. 我不认为这让我更接近解决方案,但有趣的是看到IE糟透了。

在此输入图像描述

Note: Before running tests for Firefox I cleared the cookies and cache. 注意:在运行Firefox测试之前,我清除了cookie和缓存。 I did not do this for IE or Chrome 我没有为IE或Chrome做这个

Update : Flash Loading 更新 :Flash加载

I have been sprinkling console.log statements though my code trying to sandwich the slow code. 虽然我的代码试图将慢速代码夹在中间,但我一直在使用console.log语句。 (The results get pushed out to the Firebug console). (结果被推送到Firebug控制台)。

One thing that I have noticed that seems suspicious to me me is that there is a 2.5 second gap between when my last javascript log gets printed and when my first flash log gets printed. 我注意到的一件事似乎让我感到怀疑的是,我的上一个javascript日志打印到我的第一个flash日志打印之间有2.5秒的差距。

17:08:29.973 - Javascript code
Time difference: 2510 ms
17:08:32.483 - Flash- myComponent.init()

Does flash need to setup a virtual machine for each swf? 闪存是否需要为每个swf设置虚拟机? Does it compile the actionscript on the client? 它是否在客户端上编译动作脚本?

What happens between when I <embed> my swf and when the creationComplete event in my main .mxml ? 当我<embed>我的swf和我的主.mxmlcreationComplete事件之间会发生什么?

Just some ideas: 只是一些想法:

Can you eliminate the middle man, in this case, the third party swf? 在这种情况下,你可以消灭中间人,第三方主席吗?

Where is the third party swf located? 第三方SWF在哪里? If it is on a remote server, you should just have to download it once and then place it on your local server with your other files. 如果它位于远程服务器上,您只需下载一次,然后将其与其他文件一起放在本地服务器上。 That could eliminate download times. 这可以消除下载时间。

Can you use something like a flash decompiler to decompile the third party swf's code and put the code directly into your swf? 你能用flash反编译器来反编译第三方swf代码并将代码直接放入你的swf吗? (this is probably against the rules) (这可能违反了规则)

What happens if you don't put the content in iframes, rather, just put them in divs? 如果您不将内容放在iframe中,而只是将它们放在div中会发生什么?

As another option -- try to disable firebug. 作为另一种选择 - 尝试禁用firebug。 Is time changes somehow? 时间有变化吗?

Also try the same in chrome -- with and without dev tools. 也可以在chrome中尝试相同的 - 使用和不使用开发工具。

To understand whether this jsp, that called from your swf or just your swf you can do this: 要了解这个从您的瑞士法郎或瑞士法郎调用的jsp是否可以执行此操作:

  • instead of your normal swf, provide just it mock without any calls -- just empty 而不是你的正常swf,只提供它没有任何调用模拟 - 只是空
  • also instead of your js in frame provide just empty file 而不是你的框架中的js只提供空文件

Do this partly and check the difference. 这部分做到并检查差异。

Also try to profile all newtwork events, that oocurs. 同时尝试描述所有新的事件,即oocurs。 May be your SWF calls some method in 3rd party, that calls then some remote method. 可能是你的SWF调用第三方中的一些方法,然后调用一些远程方法。 Here I think we cann't improve this. 在这里,我认为我们无法改善这一点。 Only may be if method in 3rd party could be cached somehow. 只有在第三方中的方法可以以某种方式缓存时才可能。 So in your profile we see only loading of files -- we dont' see any other requests -- ajax or something like this. 因此,在您的个人资料中,我们只看到文件的加载 - 我们没有看到任何其他请求 - ajax或类似的东西。

As per my undertanding, There are three possibilities which the suspects. 根据我的承诺,嫌疑人有三种可能性。

  1. Firebug profiler. Firebug探测器。 Try on other browser and see how much time it takes. 尝试其他浏览器,看看它需要多少时间。
  2. The Red component which is taking time after that other component might be loaded. 可能会加载其他组件后需要时间的Red组件。
  3. SWF file creating connection with other application through your server instead of direct connection. SWF文件通过您的服务器而不是直接连接与其他应用程序创建连接。

Are the iframes coming from HTML response from server? iframe是否来自服务器的HTML响应? Or, are the iframes added to DOM dynamically via javascript? 或者,是否通过javascript动态地将iframe添加到DOM?

You will have better performance by waiting until DOM is ready and inserting iframes into the DOM after page load. 等待DOM准备好并在页面加载后将iframe插入DOM中,您将获得更好的性能。

I think the problem is that Flash is blocking script execution while the local SWF downloads the 3rd party SWF. 我认为问题是Flash在本地SWF下载第三方SWF时阻止了脚本执行。 You probably need to figure out how to do a concurrent, non-blocking, asynchronous download of 3rd party SWF using ActionScript. 您可能需要弄清楚如何使用ActionScript执行第三方SWF的并发,非阻塞,异步下载。

I created a helloWorld SWF and embedded it into a web page. 我创建了一个helloWorld SWF并将其嵌入到网页中。

On the browsers that I was testing on it takes a long time for the swf to load. 在我测试的浏览器上,加载swf需要很长时间。 When there is just one swf on a page this is not noticeable (~ 3 second loading time) however when there are 10 swfs on a page there is a noticeable pause (~3 seconds/chart * 10 charts = 30 seconds). 当页面上只有一个swf时,这是不明显的(~3秒加载时间)但是当页面上有10个swfs时会有明显的暂停(~3秒/图表* 10个图表= 30秒)。

Here are the browsers that I tested on: 以下是我测试过的浏览器:

  • IE 7 - Very slow. IE 7 - 非常慢。 Takes about 37 seconds to load 16 "Hello World" applications 加载16个“Hello World”应用程序大约需要37秒
  • IE 8 - Seems mostly ok. IE 8 - 似乎很好。 Only tested for a brief period 仅测试了一段时间
  • Firefox 3.6.17 - Very slow. Firefox 3.6.17 - 非常慢。 As slow as IE 7 与IE 7一样慢
  • Chrome 12.0.742.91 - Fast Chrome 12.0.742.91 - 快速

I have posted my hello world application in another question. 我在另一个问题上发布了我的hello world应用程序。 If anyone one knows how to speed up the loading of a very simple swf you can answer here: 如果有人知道如何加快一个非常简单的swf的加载你可以在这里回答:

Flash: Many identical SWFs on same Page Flash:同一页面上的许多相同的SWF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 优化我的网站使用但不在我的网站上的Javascript和CSS? - Optimizing Javascript and CSS used BY my web site but not located ON my website? 如何使用JSP和Javascript将Applets应用程序转换为Web应用程序? - How can I convert an Applets application into an Web application using JSP and Javascript? 检测Flash应用程序是否使用Javascript正确加载? - Detect if Flash application loaded correctly using Javascript? JSP / JavaScript Web应用程序中的绝对VS相对URL - Absolute VS Relative URLs in a JSP/JavaScript web application 如何为应用程序中的所有jsp页面应用通用的JavaScript和CSS? - How to apply common JavaScript and CSS for all my jsp pages in the application? 在移动Web应用程序中使用JavaScript - Using JavaScript in mobile web application 在Web应用程序中使用Highcharts javascript - Using Highcharts javascript in Web Application JSP Web 应用程序不会使用 NetBeans 和 Z62A004B95946CA73AZ541AFA47 将数据插入数据库 - JSP Web Application Will Not Insert Data Into A Database Using NetBeans And MySQL 优化数据可视化Web应用程序的性能 - Optimizing performance of data visualisation web application 如何使用javascript从我的服务器获取数据到我的JSP? - How to get data from my Server to my JSP using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM