在空闲数小时后保持 ajax 网页正常运行

发布于 2024-08-19 11:53:42 字数 313 浏览 4 评论 0原文

我有一个单页网络应用程序,因此没有页面刷新。有时我会让页面打开一夜,然后早上回来并再次开始与其交互。通常我发现我必须刷新。 Javascript 执行不正确 - 就地编辑加载奇怪的数据,ajax 调用不触发...这与后端无关,似乎只是浏览器转储了内存,或者其他什么。不涉及任何会话。

Google 日历如何保持打开状态 3 天并仍然发出事件警报?

我有一个每 5 秒触发一次的“保持活动”调用,试图让浏览器保持警惕,但它没有帮助。有什么窍门呢?有没有办法告诉浏览器将所有内容永远保留在内存中?

(我确信网络上的许多地方都解决了这个问题,但我不知道要搜索什么。)

I have a one page web app so there is no page refreshing. Sometimes I leave the page open overnight and I come back in the morning and start interacting with it again. Usually I find I have to refresh. Javascript performs incorrectly - edit-in-place loads weird data, ajax calls don't fire... It's nothing to do with the backend, it seems to just be the browser dumping it's memory, or something. There're no sessions involved.

How does Google calendar stay open for 3 days and still fire event alerts?

I have a 'keep alive' call that fires every 5 seconds, in an attempt to keep the browser on its toes, but it hasn't helped. What's the trick? IS there a way to tell the browser to hold everything in memory forever?

(I'm sure this is addressed in numerous places on the web, but I can't figure out what to search for.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

南街女流氓 2024-08-26 11:53:42

可能需要注意的事项:

  • 在几个不同的浏览器上进行测试,看看它们是否有相同的问题。
    • 如果确实如此,那么您的代码中几乎 100% 确定有某些内容。
    • 否则可能与您当前的浏览器有关,并且可能与您的代码的某些部分进行交互。
  • 看起来微不足道,但很多人都在 javascript 中忽略了这一点,但请确保删除/释放用 new 分配的任何内容。
  • 如果您使用任何第三方库,请考虑更新它们或检查它们的论坛。

祝你好运!

Possible things to look at:

  • Test on a couple different browsers to see if they have the same problem.
    • If they do then its almost 100% certain something in your code.
    • Otherwise its probably something with your current browser and perhaps some interaction with some portion of your code.
  • Seems trivial but a lot of people over look this in javascript, but make sure you are deleteing/freeing anything you allocate with new.
  • If you use any 3rd party libraries consider updating them or checking their forums.

Good luck!

無處可尋 2024-08-26 11:53:42

当您刷新页面时,是否由于会话超时或其他原因而需要进行任何身份验证?因为如果您真正需要做的就是按 F5 就可以了,我建议您在应用程序中创建一个“空闲”计时器,如果没有交互(IOW 重置),每小时执行一次 window.reload()每次有互动时的计时器)

希望这有帮助

When you refresh the page do you need to do any authentication because of a timed-out session or anything ? Because if all you really need to do is hit F5 and you're good to go, I would suggest you create an 'idle' timer in your app that does a window.reload() every hour if there is no interaction (IOW reset that timer each time there is an interaction)

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文