←back to thread

217 points palmfacehn | 1 comments | | HN request time: 0s | source
Show context
alserio ◴[] No.45107190[source]
I was wondering, are template elements a good place to store json data in the page to be consumed by js?
replies(4): >>45107213 #>>45107278 #>>45108146 #>>45108459 #
jfagnani ◴[] No.45108459[source]
No. I would use <script type="-json">

<script> parses its contents as text, whereas <template> parses as DOM. This means you don't have to escape `<`, just `</script>`.

Myself and some browser engineers been working on proposals to allow for inline modules, including JSON, that are importable into other modules via regular import statements.

This is why I recommend the "-json" type - so it doesn't collide with a future native "json" type.

replies(2): >>45108658 #>>45108871 #
1. alserio ◴[] No.45108871[source]
Thank you. And that proposal seems really interesting. Can I ask for a link if you happen to have one publicly accessible?