Chrome doesn't show file as being downloaded until 8 bytes are sent (Firefox does) Chrome doesn't show file as being downloaded until 8 bytes are sent (Firefox does) google-chrome google-chrome

Chrome doesn't show file as being downloaded until 8 bytes are sent (Firefox does)


You could try prepending the file with 0-width space characters.

const express = require('express');const app = express();const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))app.get('/:type?', async (req, res) =>  {  res.set("Content-type", "application/octet-stream");  res.set("Content-Disposition", "attachment; filename=\"Report.txt\"");  res.write('\u200B\u200B\u200B\u200B\u200B\u200B\u200B\u200B');   //res.write('1234567');   if (req.params.type == "instant")    res.write('8'); //if I send 8 bytes before sleep, file downloading appears instantly  await sleep(4*1000);  res.write('9');  res.end();});app.listen(3000, () => {  console.log('server started');});