node.js - show progress during processing big data -
i have question have web app run need process big file. can take 5secund meantime want show user file processing or best send information how many time end. first page , cannot send twice res.render how this?
var fileinarray = require('./readfile'); app.get('/', function(req, res){ var dataready = fileinarray; res.render('index', {data: dataready}); }); so how can his? read little socke.io don't how used in case?
thank help
if loading page (which looks like) request, can't show progress way have structured because browser waiting download page , can't show in window until render page it. but, want show progress before page gets there.
so, have restructure way things work. first off, in order show progress, browser has have working page can show progress in. means browser can't waiting page arrive. straightforward way can think of render shell page server returns (no waiting original content). in shell page, have code show progress , initiate request server fetch long running data. there several ways done using ajax , websockets. i'll outline combinations:
all ajax
- browser requests / page , server renders shell page
- meanwhile, after rendering page, server starts long running process of fetching desired data.
- rendered inside shell page javascript variable contains transaction id
- meanwhile, client-side javascript can regularly send ajax requests server check on progress of given transaction id (say every 10 seconds). server returns whatever useful progress info , client-side javascript displays progress info.
- at point server done data , 1 of regular ajax requests checking on progress returns data. client-side javascript inserts data current page , operation complete.
mostly websocket
- browser requests / page , server renders shell page
- client-side code inside shell page makes websocket or socket.io connection server , sends initial request data belongs page.
- the server receives websocket connection , initial request data , starts long running process of fetching data.
- as server has meaningful progress information, sends client on websocket/socket.io connection , when client receives information, renders appropriate progress in page.
- at point server done fetching data , sends client message containing final data. client-side javascript receives data , inserts page.
- the client can close websocket/socket.io connection.
Comments
Post a Comment