Webkit线程化javascript文件加载和执行顺序

Webkit线程化javascript文件加载和执行顺序

本文介绍了Webkit线程化javascript文件加载和执行顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个XSS小部件,并且我遇到了Webkit浏览器加载外部javascript文件的问题,我将这些文件附加到dom中。它的工作原理如下:

I am trying to building a XSS widget and am having issues with Webkit browsers loading the external javascript files which I am appending into the dom. It works as below:


  • Widget.js将3个javascript文件追加到dom(jquery,data,content)

  • Jquery.js是带有自定义命名空间的标准jquery

  • Data.js是一个javascript数组

  • Content.js是一个集合基于Data.js中的数据构建窗口小部件的jQuery指令

  • Widget.js appends 3 javascript files into the dom (jquery, data, content)
  • Jquery.js is standard jquery with a custom namespace
  • Data.js is a javascript array
  • Content.js is a set of jQuery instructions to build the widget based off the data in Data.js

在firefox中浏览器确实100%的时间做了什么我告诉它和小部件加载你在页面上放置包含javascript的地方。

In firefox the browser does exactly 100% of the time what im telling it and the widget loads where ever you placed the include javascript on the page.

然而在Webkit即Safari中,浏览器以随机顺序返回3个文件,并在返回后执行。这意味着当Content.js查找$来执行jquery魔术时它会失败。同样,如果jQuery可用,并且由于缺少数据而导致数据延迟加载数据。

However in Webkit ie Safari, the browser returns the 3 files in a random order, and executes once returned. This means that when Content.js looks for $ to do jquery magic it fails. Likewise if jQuery is available and it loads the data late if fails due to lack of data.

建议?

推荐答案

执行此操作的最佳方法是仅连接服务器上的文件 - 这样您就可以制作3个http请求一个,脚本一起解析和执行。

The best way to do this is to just concatenate the files on the server--that way you go from making 3 http requests to one, and the scripts are parsed and executed together.

如果你不能这样做,你是否必须通过将脚本标签附加到dom来添加脚本标签?如果您只是在HTML中添加它们,它应该可以工作:

If you can't do that, do you have to add the script tags by appending them to the dom? If you just added them in HTML, it should work:

<script src="widget.js"></script>
<script src="jquery.js"></script>
<!--etc -->

这篇关于Webkit线程化javascript文件加载和执行顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 05:35