1

I'm trying to display a chart of averages/trends of a lot of data in a Django application. I went the route of embedding the data in the template, similar to:

<script>
  var data = JSON.parse({{ giant_json_of_data }});
</script>

And on a page where that data is really really big, the part of my HTML with that script in it isn't even showing up.

This is similar to this question, but my browser isn't throwing any error message -- it's just not displaying the relevant part of the template at all!

Is there a limit to how big of a json string you can embed in a template?

Community
  • 1
  • 1
Brendan W
  • 3,303
  • 3
  • 18
  • 37

1 Answers1

1

What volume of data are we talking about ? Megabytes ?
Have you tried with a smaller amount of data instead ? Does it display correctly ?

In any case, I think there are most efficient ways to solve this than embedding JSON directly in template. Especially, if you have so much data, the page loading could result in a timeout.

What about loading these data asynchronously in smaller chunks on the client-side with Ajax ?

Agate
  • 3,152
  • 1
  • 19
  • 30
  • I'm not sure in terms of bytes how long it is. At least a couple hundred lines when you print it out in a console... Maybe a couple thousand lines. Probably too long to embed. And with a smaller amount of data: yeah it renders OK. The current plan is to load it with ajax calls, but I'm just perplexed by the whole thing failing silently and just not showing up in the template/inspect element! – Brendan W Aug 06 '15 at 21:06
  • I think browsers may react differently when exposed to huge amount of data. Does is still fails silently when switching to another browser? – Agate Aug 07 '15 at 08:41