I would use JSON in the <script> element. In fact, I would make it an actual script. The browser will analyze and evaluate JSON, so take the opportunity to save it in some variable.
Hiding elements with CSS is pretty fragile, as some clients (not necessarily browsers thinking search engines) can still see them as part of the pageโs data.
Downloading data via XHR after loading the page is fine, but this is not strictly the answer to the question. It is also a bit slower as it carries an extra server round (think about your antipodey users, low latency is very important for them).
XML data islands: I'm not sure what you're talking about, but it looks like it can cause a lot of complaints about the validator and can be fragile in that the node string can be displayed by the browser.
So, storing data in a <script> element sounds like the easiest, safest, and most appropriate way to answer a question.
source share