Progressive Enhancement for long-running tasks
I'm looking for ways to improve a web page that initiates a 开发者_Go百科long-running (>2 minutes) server-side task. The current version of the page just clocks for the full duration of the task, which can be very frustrating to the user.
I already have a few ideas about how I could improve the user's experience, but they all would involve the use of AJAX to some extent. Because of previous experiences that I've had on this project, I know that not all users have JavaScript enabled or available.
Assuming that the server-side process has already been optimized as much as possible, what else could I do to improve the experience of all users as much as possible?
Move the long-running server process out-of-band.
When users initiate the task the application can write a message to a queue of some sort; this is typically extremely fast, so users get control back quickly. Once the message is queued, another specialized process (a service, a scheduled task, a cron job, etc.) picks it up and executes the appropriate task at the first opportunity.
For users with javascript enabled, you can set up a timer to check the status of the task via AJAX and alert them when the task is finished.
You can keep your non-javascript users informed by displaying their pending and completed tasks in a common, visible spot on your pages. Of course, they have to keep browsing to benefit from that, so you also need to make it clear that users should occasionally refresh the page if they're waiting for a task to finish.
- create table in database (or in-memory object)
- long-running task will update progress in this table (object)
- web page will display data from this table (or object). how to refresh page - it's your choice.
精彩评论