A performance trick that’s been doing rounds on Twitter, now available as a video:
Because the JSON grammar is much simpler than JavaScript’s grammar, JSON can be parsed more efficiently than JavaScript. This knowledge can be applied to improve start-up performance for web apps that ship large JSON-like configuration object literals (such as inline Redux stores).
So instead of assigning a JS object to your store, assign the output of JSON.parse('{…}')
to it.
There’s also a Babel plugin named babel-plugin-object-to-json-parse
available that can automatically adjust your code for you.
👍 Great to hear Mathias sport the biggest web caveat there is: “It Depends”
There are a few people that says they your best not to.
https://medium.com/@pmzubar/why-json-parse-json-stringify-is-a-bad-practice-to-clone-an-object-in-javascript-b28ac5e36521
https://medium.com/ft-product-technology/this-one-line-of-javascript-made-ft-com-10-times-slower-5afb02bfd93f
This is a completely different use of JSON.parse tho