Requirejs加载插件
我正在尝试使用 requirejs 加载插件,但偶尔会出现错误,“$.fn 未定义”,但如果我重新加载页面,错误就会消失,就像现在 jquery 被缓存一样,问题就被消除了。我正在像这样加载我的库:
require(["jquery-1.4", "/script/jquery.autoSuggest.packed.js"], function($) {
$(function() {
//code
});
});
您能看看此实现是否有任何问题会导致此错误吗? Require js 被添加到页面中,如下所示:
<script type="text/javascript" src="http://website.co.uk/frameworks/requirejs/0.2.4/sharedmodules/require.js">
</script>
<script type="text/javascript"> requireMap = {
"jquery-1.4":"http://website.co.uk/sharedmodules/jquery-1.4"
};
require({ baseUrl: 'http://website.co.uk/', paths: requireMap });
</script>
这是无法更改的,因为它是我正在使用的框架的一部分。
有什么建议吗?
谢谢!
I'm trying to load a plugin using requirejs but occasionally get an error, "$.fn is undefined" but if I reload the page the error disappears almost like now jquery is cached the problem is removed. I'm loading my libraries like this:
require(["jquery-1.4", "/script/jquery.autoSuggest.packed.js"], function($) {
$(function() {
//code
});
});
Can you see if there is anything wrong with this implementation that would cause this error? Require js is being added to the page as so:
<script type="text/javascript" src="http://website.co.uk/frameworks/requirejs/0.2.4/sharedmodules/require.js">
</script>
<script type="text/javascript"> requireMap = {
"jquery-1.4":"http://website.co.uk/sharedmodules/jquery-1.4"
};
require({ baseUrl: 'http://website.co.uk/', paths: requireMap });
</script>
This can't be changed as it's part of the framework I'm using.
Any suggestions?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
订单插件已删除。使用填充程序加载如下
参考: http://requirejs.org/docs/api.html#config-shim
order plugin is removed. use shim loading as follows
reference : http://requirejs.org/docs/api.html#config-shim
您将需要使用订单插件。默认情况下,RequireJS 会尽快加载脚本,并且它们可能会乱序加载。但是,顺序插件将保持脚本加载的顺序。
如果您使用优化器来优化脚本,请确保在优化的脚本中包含 jQuery 和插件。
You will want to use the order plugin. By default RequireJS loads scripts as fast as possible, and they can load out of order. However, the order plugin will maintain the order of the script loads.
If you use the optimizer to optimizer your scripts, be sure to include both jQuery and the plugin in the optimized script.
您可能需要查看 https://github.com/jquery-boilerplate/patterns
它有一些很好的样板 jQuery 插件代码,可以与 RequireJS 一起使用。
我认为您可能必须将 jQuery 升级到 1.7,然后这些模式才能为您工作。
You may want to checkout https://github.com/jquery-boilerplate/patterns
It has some good boilerplate jQuery plugin code that will work with RequireJS.
I think you may have to upgrade your jQuery to 1.7 before these patterns will work for you.