PHP:请求50MB-100MB json - 浏览器崩溃/不显示任何结果

Huge json server requests: around 50MB - 100MB for example.

From what I know, it might crash when loading huge requests of data to a table (I usually use datatables), the result: memory reaches to almost 8G, and the browser crash. Chrome might not return a result, Firefox will usually ask if I want to wait or kill the process.

I'm going to start working on a project which will send requests for huge jsons, all compressed (done by the server side PHP). The purpose of my report is to fetch data, and display all in a table - made easy to filter and order. So I cant find the use of "lazy load"ing for this specific case.

I might use a vue-js datatable library this time (not sure which specifically).

  • What's exactly using so much of my memory? I know for sure that the json result is received. Is that rendering/parsing of the json to the DOM? (I'm referring to the datatable example for now: https://datatables.net/examples/data_sources/ajax)

  • What is the best practices in these kind of situations? I started researching this issue and noticed that there are posts from 2010 that seem like they're not relevant at all.

There is no limit on the size of an HTTP response. There is a limit on other things, such as:

  • local storage
  • session storage
  • cache
  • cookies
  • query string length
  • memory (per your CPU limitations or browser allocation)

Instead, the problem is with your implementation of your datatable most likely. You can't just insert 100,000 nodes into the DOM and not expect some type of performance impact. Furthermore, if the datatable is performing logic against each of those datum as they're coming in and processing them before the node insertion, that's also going to be a big no no.

What you've done here is essentially pass the leg work of performing pagination from the server to the client, and with dire impacts.

If you must return a response that big, consider using one of the storage options that browsers provide (a few mentioned above). Then paginate off of the stored JSON response.