JavaScript文件的依赖 - 选择性加载资源文件和放大器; prevent重复 [英] Javascript file dependencies - Selective load resource files & prevent duplicates
本文介绍了JavaScript文件的依赖 - 选择性加载资源文件和放大器; prevent重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能更多的是哲学辩论的,但这里是我的:
This might be more of a philosophical debate, but here is what I have:
- 在两个控件,它们共享一个Javascript资源库调用Web服务。
- 它们后容易配合使用对方,但并非总是如此。
- 在该javacsript文件他们都引用不容易分开。
- JavaScript文件不应该在应用程序添加到每个页面。
在理想情况下我会分裂的控件之间的web服务,让每个呼叫的目标只是为了他们所需要的功能一个js资源文件。
Ideally I would divide the webservice between the controls and have each call a js resource file targeted just to the functionally they need.
我不知道是否有一个明显的更好的方法,我很想念......
I'm wondering if there is an obvious better way that I'm missing...
在其最简单的形式I具有:
In its simplest form I have:
<html>
<head>
</head>
<div>
<h1>Control1</h1>
<script type="text/javascript" src="/Webservice.asmx/js"></script>
</div>
<div>
<h1>Other stuff</h1>
</div>
<div>
<h1>Control2</h1>
<script type="text/javascript" src="/Webservice.asmx/js"></script>
</div>
</body>
</html>
修改
我有jQuery的提供给我,如果这提供了一个有用的方法。
Edit
I have jQuery available to me if this provides a helpful method.
使用ASP.NET
推荐答案
解决具有以下JS&放我的问题; jQuery的code
Solved my issue with the following JS & jQuery code
if (thisResourceLoaded === undefined)
{
$.getScript('/Webservice.asmx/js');
var thisResourceLoaded = true;
}
这篇关于JavaScript文件的依赖 - 选择性加载资源文件和放大器; prevent重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文