简体   繁体   English

使用 dojo 向服务器发出许多请求

[英]Many requests to server with dojo

dojo.require("dijit.Dialog");
dojo.require("dijit.form.Form");
dojo.require("dijit.form.Button");
dojo.require("dijit.form.DateTextBox");
dojo.require("dijit.form.TimeTextBox");
dojo.require("dijit.form.ValidationTextBox");
dojo.require("dijit.layout.TabContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.Tooltip");
dojo.require("dojo.parser");
dojo.require("dojo.fx");
dojo.require("dojo.dnd.Manager");
dojo.require("dojo.dnd.Source");
dojo.require("dojox.layout.ContentPane");
dojo.require("dojo.io.iframe");

This appears with CDN or with src="", and show in inspect element in my page a lot of requests, someone know why?这与 CDN 或 src="" 一起出现,并在我的页面中的检查元素中显示了很多请求,有人知道为什么吗?

Well, It seems you want to understand the flow of Dojo I mean how it works and how it loads its dependencies.好吧,您似乎想了解flow of Dojoflow of Dojo我的意思是它如何工作以及如何加载其依赖项。

In above snippet code as we can see you are using legacy model/version of dojo在上面的代码片段中,我们可以看到您使用的是 旧版模型/dojo 版本

First we understand the require and define首先我们了解requiredefine

require and define are part of the asynchronous module definition (AMD) API. requiredefine是异步模块定义(AMD) API 的一部分。

You use define to define a module that can be consumed by other code.您可以使用define来定义一个可以被其他代码使用的模块。 Generally, define will be used in a javascript file.通常, define将用于 javascript 文件中。 The javascript file is defining a module. javascript 文件正在定义一个模块。 All Dojo files use define.所有 Dojo 文件都使用define。

You use require when you are not defining a module, but you require modules that have been defined.当您不定义模块但需要已定义的模块时,您可以使用require

Loading of widgets加载小部件

So in your network and console you can observe that whenever you load the dojo cdn link it simply loads the init.js default loader file.因此,在您的网络和控制台中,您可以观察到,每当您加载 dojo cdn 链接时,它只会加载init.js默认加载器文件。 very small in size and easy/faster to load.体积非常小,加载容易/更快。

So once your dojo loader is loaded based on your dojo configuration then it start looking for dependencies which you are using in your project so which ever widgets ( dojo controls, classes, files etc. ) you mentioned in require it will start loading those widget from CDN.因此,一旦您的 dojo 加载器根据您的dojo 配置加载,它就会开始寻找您在项目中使用的依赖项,以便您在 require 中提到的小部件( dojo controls, classes, files etc. )将开始从以下位置加载这些小部件CDN。

In this case dojo doesn't load the whole dojo library in your prject it simply loads only those widgets which you mention in require .在这种情况下,dojo 不会在您的项目中加载整个 dojo 库,它只会加载您在require提到的那些小部件。

Hoping this will answer your concerns :)希望这能解决您的疑虑:)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM