English 中文(简体)
Unusual javascript HTTP caching / undefined issues
原标题:

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!!

问题回答

If you have the Webdevelopers toolbar installed in Firefox, activate "Disable Cache" it helps a lot on debugging.

start calling the first js function after! the page has loaded, do this by <body onload="startmyfunction()"> or similar.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签