Best way to store JSON in an HTML attribute?

后端 未结 9 1534
梦毁少年i
梦毁少年i 2020-11-30 19:57

I need to put a JSON object into an attribute on an HTML element.

  1. The HTML does not have to validate.

    Answered by Quenti

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 20:08

    The HTML does not have to validate.

    Why not? Validation is really easy QA that catches lots of mistakes. Use an HTML 5 data-* attribute.

    The JSON object could be any size (i.e. huge).

    I've not seen any documentation on browser limits to attribute sizes.

    If you do run into them, then store the data in a

提交回复
热议问题