Requirejs随机调用我的服务器进行依赖

时间:2014-05-14 21:51:29

标签: javascript requirejs

在文档(http://requirejs.org/docs/api.html)中:

// contents of main.js:
require.config({
    paths: {
        foo: 'libs/foo-1.1.3'
    }
});

// contents of other.js:

// This code might be called before the require.config() in main.js
// has executed. When that happens, require.js will attempt to
// load 'scripts/foo.js' instead of 'scripts/libs/foo-1.1.3.js'
require( ['foo'], function( foo ) {

});

在我的情况下,路径设置在“要求”之前。声明,在同一个函数中,在同一个文件中:

loadBaseTemplates: function () {
            var self = this;

            //add path for future reference
            require.config({
                paths: {
                    'templates-base': globalProperties.urlPrefix + '/org/dust-ui/dist/js/templates/base/dustc' + self.platformType + '-min-' + globalProperties.swapFileVersion
                }
            });

            //load base templates
            require(['templates-base'], function () {
            });
        }

非常非常罕见的事件(不到总流量的1%),我的服务器日志中出现以下错误,这意味着浏览器正在为templates-base.js发出GET请求

127.0.0.1 - - [13/May/2014:22:47:52 +0000] "GET /org/actions/templates-base.js HTTP/1.0" 500 575 1 "Mozilla/5.0 (Windows NT 5.1; rv:29.0) Gecko/20100101 Firefox/
29.0"

这似乎与任何特定浏览器无关。

需要注意的另一件事是我正在使用优化工具。

非常感谢任何帮助或见解!

更新:

添加所有出现的' templates-base'在我的申请中。这里粘贴的所有代码都在同一个文件中。

  if (contentJSON.arguments.needsCountryTemplates && contentJSON.arguments.needsClientTemplates) {
        require(['templates-base', 'templates-country', 'templates-client'], function () {

        });
    } else if (contentJSON.arguments.needsCountryTemplates) {
        require(['templates-base', 'templates-country'], function () {

        });
    } else if (contentJSON.arguments.needsClientTemplates) {
        require(['templates-base', 'templates-client'], function () {

        });
    } else {
        require(['templates-base'], function () {

        });
    }

第一个需要阻止:

require(['utility', 'jquery', 'dust'], function(utility) {
   $(function() {
       utility.setPlatformType();
       utility.loadBaseTemplates();
   });
});

0 个答案:

没有答案
相关问题