0

我在 Chrome 和 IE 中发生过这种情况......

如果我在 requirejs 仍在加载或获取脚本时单击链接以离开页面,我会收到随机错误。对不起,如果这是模糊的......

例如,在 require.js 本身,我今天收到一个错误:

Unable to get value of the property 'normalize': object is null or undefined 

在以下块中:

//If current map is not normalized, wait for that
                //normalized name to load instead of continuing.
                if (this.map.unnormalized) {
                    //Normalize the ID if the plugin allows it.
                    if (plugin.normalize) {
                        name = plugin.normalize(name, function (name) {
                            return normalize(name, parentName, true);
                        }) || '';
                    }

                    //prefix and name should already be normalized, no need
                    //for applying map config again either.
                    normalizedMap = makeModuleMap(map.prefix + '!' + name,

我在自己定义的 js 文件中收到了其他错误,它们在完全加载依赖项之前开始执行代码。我感觉当浏览器被要求离开当前页面时,它会停止所有 ajax 调用,从而截断一些 js。

有没有办法防止这类错误?

4

1 回答 1

0

避免在define函数范围内运行代码。加载所有内容后,通过在页面准备好时执行的函数中编写代码来启动应用程序的逻辑。

还有你说的导航是什么意思?如果您离开页面,页面以及它的错误都会消失。这种 pushAPI 风格的导航是应用程序保持加载状态,还是完整且完整的浏览器导航?

于 2013-09-20T17:23:44.907 回答