0

One of my models has a field where I store very large arrays. My frontend app has to load all of them at once which makes the request response a bit slow. I was thinking of compressing the arrays in the backend and decompressing in my react frontend application, is it possible?

Akira Kotsugai
  • 1,099
  • 3
  • 12
  • 19
  • You could use [`gzip`](https://docs.djangoproject.com/en/dev/ref/middleware/#module-django.middleware.gzip) since your browser knows how to decompress it automatically as long as the headers are correct (which the middleware sets). – cbr Jan 17 '20 at 20:24
  • Could you please provide me with an example? What headers should be correct? And how is it automatically decompressed? Does the response body already return the matrix? – Akira Kotsugai Jan 17 '20 at 20:31
  • Consider caching as well. – engin_ipek Jan 17 '20 at 20:58
  • How are you downloading this array from your app? You could consider using a streaming http response if it is a file like object – Iain Shelvington Jan 17 '20 at 21:06
  • In Django, you can add GZip middleware to your app by adding the line `'django.middleware.gzip.GZipMiddleware'` to the `MIDDLEWARE` list in `settings.py`. – mkkekkonen Jan 17 '20 at 21:22
  • See [this answer](https://stackoverflow.com/a/1864377/4509338). – mkkekkonen Jan 17 '20 at 21:24

0 Answers0