JavaScript-How do I get updated data from a database when I send events with the server (server-sent events)?

Source: Internet
Author: User
I think of two ways:
1. Take the data from the most recent period of time, if any, return the data, but this time period is not good set, chrome can use the last 3 seconds, and Firefox is the last 5 seconds, take 3 seconds, Firefox is often not available, take 5 seconds, Chrome will appear to remove duplicate data.

2. The second idea is whether the database to mark is read, but because different browsers, different terminal data is not synchronized, one of the data is identified as read, the other browser will not get the data.

So, what should be done?

Reply content:

I think of two ways:
1. Take the data from the most recent period of time, if any, return the data, but this time period is not good set, chrome can use the last 3 seconds, and Firefox is the last 5 seconds, take 3 seconds, Firefox is often not available, take 5 seconds, Chrome will appear to remove duplicate data.

2. The second idea is whether the database to mark is read, but because different browsers, different terminal data is not synchronized, one of the data is identified as read, the other browser will not get the data.

So, what should be done?

The second way of thinking can, but to optimize, can be in the table memory data update time, in the terminal storage from the server to get the latest data update time, the terminal time is smaller than the table time, it represents the new data to push.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.