Picture you have a website that has comments on. Your website is online and running but everytime a minute passes your comments get older and they change from this: "3 minutes ago" to this " 5 minutes ago" , "one hour ago" etc.
How would you go about doing that? Would you spawn a thread? I'm not really sure how I can start just one thread when the app is deployed, or when it aknowledges that the database has comments. Any help appreciated!
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
The Web is neither asynchronous nor continually-connected.
If a web page wants to be updated, it has 2 choices:
2. Make a request to the server. The server will then respond with the update back to the requester and disconnect until the next request.
Got idle CPU cycles? Join the war on COVID-19 by donating them to find the coronavirus' weak spots. folding@home Runs in the background. https://foldingathome.org
The fact that you want to update how old a comment is probably means (I could be very wrong of course) that you are soon going to need to be able to show new comments when they are available without the user needing to refresh as well. If your application is driven by many such requirements of the server notifying the client for updates then you should consider adding full duplex communication with websockets to the application.
I don't know much about websockets, but my application is polling the database for new comments with ajax (setInterval(function(), time)), so no need for refresh there. I slaved at that thing for days. I will probably just date them, like javaranch is doing it, and present it for the users specific timezone. Thanks for helping!
Live ordinary life in an extraordinary way. Details embedded in this tiny ad: