Sometimes you can have massive static objects. Like a list of emojis and their codepoints.[1] It could be useful in cases like that. You'd have to experiment, though.
[1] https://raw.githubusercontent.com/joypixels/emoji-toolkit/ma...
Since we compile JavaScript to an unreadable mess anyway... Why not?
That's...what the article proposes, so yes?
The key part here is
> As long as the JSON string is only evaluated once the JSON.parse approach is much faster.
So doing this would only work on top-level declarations, because the javascript runtime will cache the parsed JSON structure for subsequent executions (eg. creating an object in a loop).
Re:The cost of parsing JSON
by nostrademons on Wednesday September 18, 2019 @01:12PM
(#21007525)
WebPack, properly configured, will let you import plain old .json files through the normal es6 import mechanism. It doesn't use this technique though: the JSON file is treated as normal JS source (preprocessed to remove unnecessary quotes etc.) and wrapped with an export.
Not sure if I should end this comment with a /s or not.