This content originally appeared on CSS-Tricks and was authored by Chris Coyier
Dr. Axel Rauschmayer looks at JSON modules, which is already live in Chrome 91 (but nothing else). It looks just like an ES Modules-style import, only you asset the type at the end.
import configData from './config-data.json' assert {type: 'json'};
How nice is that? Once this makes its way across browsers, we’ve gone on a journey from “you’ll almost definitely want to use an Ajax library” because of the cross-browser complexity and weirdness of XMLHttpRequest
to the much nicer (but you still gotta write some code) fetch API, to a one-liner (if what you need is JSON data).
Snagging some JSON data seems like it should be as easy as a one-liner to me, and now it is. I like how the URL can be dynamic now too.
Direct Link to Article — Permalink
The post ECMAScript proposal: JSON modules appeared first on CSS-Tricks. You can support CSS-Tricks by being an MVP Supporter.
This content originally appeared on CSS-Tricks and was authored by Chris Coyier

Chris Coyier | Sciencx (2021-07-21T21:08:08+00:00) ECMAScript proposal: JSON modules. Retrieved from https://www.scien.cx/2021/07/21/ecmascript-proposal-json-modules-2/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.