I'm not sure if I worded this correctly, but let me try to explain it.
I'm often finding myself in a situation that my server will send the following html snippet on a page request :
<div id="my-values" data-values="[1,2,3,4,5]">Values</div>
And then javascript uses JSON.parse to use those values to generate something.
But I always feel like I'm taking so much unecessary steps.
1) Server serializes the values into the html and sends it
2) Client Javascript does a query selector to find the element that holds the values
3) Client Javascript then parses the values back to be useable
Is there a way to skip the serialization/deserialization?
I have control over both server and client code so there has to be a better way of them communicating.
Hope I have been clear, maybe there is a name for this common issue.
Please note that I'm discarding things like SPA, I'm looking for server-side rendering and maximum SEO efficiency.
One idea I thought about is, instead of the server parsing the values into HTML, it could parse into javascript, a sort of javascript template (sounds weird and wrong)
(tagging flask as that's the server I'm using but doesn't matter for the answer)