不寻常的 javascript HTTP 缓存/未定义问题
好的。我以前从未见过这样的东西,我很困惑......在我正在开发的网站上,有两个 JavaScript 包含。 (嗯,还有很多,但只有两个就会出现问题)。我们将它们称为 A.js
和 B.js
。
A.js
定义了一个 JavaScript 单例 A
。同样,B.js
定义了一个 JavaScript 单例 B
。 B
类依赖于 A
中的方法。
我几乎将所有代码都包含在 try { ... } catch { ... }
块中,并且在出现错误时,系统会生成一个 AJAX 请求,通过电子邮件向我发送错误的详细信息。
在我办公室的一个系统(Mac 版 Firefox 3.0)上,我看到了最奇怪的行为。偶尔,也许每小时或每两个小时一次,但没有特定模式,我会收到来自 B
类的错误电子邮件:“ReferenceError:A 未定义。”
I不知道为什么/如何 A
有时会未定义。当我查看 apache 日志时,在收到错误期间,客户端在请求 /B.js
之前正在请求 /A.js
,并且服务器正在请求使用 304
(未修改)进行响应,
我以某种方式怀疑问题是客户端缓存中的文件已过期,但是服务器不发送该文件,因此它永远不会被执行,并且 A
未定义。但这只是猜测,我不明白为什么会发生这种情况。如果我猜对了,我该如何解决它?
如果重要的话,请在服务器上启用 mod_disk_cache
,并且我已将其禁用以查看是否是导致问题的原因。如果是这样,也许这属于 ServerFault...
非常欢迎任何建议!
Ok. I have never seen anything like this before and I am quite confused... On a website I am working on, there are two JavaScript includes. (Well, many more, but the problem occurs with only two). We'll call these A.js
and B.js
.
A.js
defines a JavaScript singleton A
. Likewise B.js
defines a JavaScript singleton B
. The B
class depends on methods from A
.
I have almost all my code wrapped up in try { ... } catch { ... }
blocks, and on error, the system generates an AJAX request to email me the details of the error.
On one system here in my office (Firefox 3.0 for Mac) I am seeing the strangest behavior. Once in a while, maybe once every hour or two, but with no specific pattern, I get an error email from class B
: "ReferenceError: A is undefined."
I have no idea why/how A
would be undefined sometimes. When I look in the apache logs, during the times I receive the error, the client is requesting /A.js
, before requesting /B.js
, and the server is responding with a 304
(Not Modified)
I somehow suspect the issue is that the file has expired from the client cache however the server doesnt send the file thus it is never executed and A
is undefined. But that's just a guess and I don't understand why that would happen. And if I am guessing right, how do I fix it???
If it matters, mod_disk_cache
was enabled on the server, and I have disabled it to see if that was causing the problem. If so, maybe this belongs on ServerFault...
Any suggestions very welcome!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在 Firefox 中安装了 Webdevelopers 工具栏,请激活“禁用缓存”,这对调试有很大帮助。
If you have the Webdevelopers toolbar installed in Firefox, activate "Disable Cache" it helps a lot on debugging.
之后开始调用第一个js函数!页面已加载,请通过
或类似方法执行此操作。
start calling the first js function after! the page has loaded, do this by
<body onload="startmyfunction()">
or similar.