Faster JavaScript Apps with JSON.parse()

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”

Join the Conversation


Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.