Ben Wong Ben Wong - 1 year ago 250
Javascript Question

Javascript: Exporting large text/csv file crashes Google Chrome

I have the following Javascript code to export CSV file on the client side. However Google Chrome crashes every time I try to export a large array. What is the limit of the data string allowed in Chrome? Is it possible that it is hitting the memory limit allowed in Chrome? If the data string is too long for Chrome, how will I go about exporting large CSV files on the client side?

var csvRows = [...]; //Array with 40000 items, each item is 100 characters long.

var csvString = csvRows.join("\r\n");

var a = document.createElement('a');

a.href = 'data:text/csv;charset=utf-8,' + encodeURIComponent(csvString); = '_blank'; = 'export.csv';


(Expected file size is about 6.4MB)

jan jan
Answer Source

had the same Problem and solved it using Blobs.

For your example:

csvData = new Blob([csvString], { type: 'text/csv' }); 
var csvUrl = URL.createObjectURL(csvData);
a.href =  csvUrl;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download