gdp*_*gdp 6 timeout requirejs asp.net-mvc-5
要求js在没有捆绑的情况下正常工作.但每当我使用捆绑包时,我都会为我要导入的模块获得超时.
以下是我使用asp.net mvc bundler/minifier构建软件包的方法
bundles.Add(new ScriptBundle("~/bundles/test").Include(
"~/scripts/jquery-{version}.js",
"~/scripts/bootstrap.js",
"~/scripts/moment.js"));
bundles.EnableOptimizations = true;
Run Code Online (Sandbox Code Playgroud)
Heres是cshtml文件中的require js config:
<script>
require.config({
baseUrl: "/scripts",
paths: {
jquery: "jquery-1.11.2"
},
waitSeconds: 20,
shim: {
bootstrap: {
deps: ['jquery']
}
},
bundles: {
'@Scripts.Url("~/bundles/test").ToString()': [
'jquery',
'bootstrap',
'moment'
]
}
});
require(["app/main/test"]);
</script>
Run Code Online (Sandbox Code Playgroud)
页面的js(app/main/test):
require(['jquery', 'moment'], function ($, moment) {
console.log(moment().format());
});
Run Code Online (Sandbox Code Playgroud)
Jquery,bootstrap和moment库都在我创建的测试包中,但是我加载页面暂时加载超时.
这是chrome检查器错误:

有任何想法吗?
提前致谢.
发生这种情况是因为您根本不需要您的捆绑包。您的 require 调用只有 jquery 和 moment。您已经提供了 jquery 文件路径,因此 requirejs 使用该路径下载并提供 jquery 模块。但由于暂时没有路径定义,它只是您创建的包的一部分。因此 requirejs 尝试通过其模块名称作为路径下载 moment,从而引发错误。
解决此问题的一个简单方法是需要捆绑包本身。
require(['@Scripts.Url("~/bundles/test").ToString()'], function(bundle){
//At this point jquery, moment and bootstrap will be loaded.
});
Run Code Online (Sandbox Code Playgroud)
您可以选择直接使用上例中全局命名空间中的 jQuery、moment,也可以尝试在下例中单独使用它们。我不确定,但由于循环依赖,您可能会在下面的示例中遇到错误。
require(['@Scripts.Url("~/bundles/test").ToString()', 'jquery', 'moment'], function(bundle, $, moment){
//At this point jquery, moment and bootstrap will be loaded.
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
435 次 |
| 最近记录: |