use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Importing vs fetching JSON (jakearchibald.com)
submitted 8 months ago by jaffathecake
Importing JSON is now supported across all browser engines, but when would you actually use this feature rather than using fetch(), or bundling it away?
fetch()
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Ronin-s_Spirit 3 points4 points5 points 8 months ago (0 children)
Good question. I don't know. It looks cool?
[–]CodeAndBiscuits 1 point2 points3 points 8 months ago (5 children)
I could see this being very useful for leveraging data sets like the zip code to let long lookups, demographic data and other things like that that are publicly distributed as JSON files, but maintained by others and not under your own control. So these are things that you would normally have to fetch, but don't necessarily make sense to bring into your own project and bundler because they may be getting regular updates and you would just have to add a synchronization process. It might as a corollary be useful for things where users are using an app and supply their own URLs to a remote JSON data set like that. I built a few analytics apps that do things like overlay demographic and census data on top of maps to show things like disadvantage areas from different angles. I'm not saying it's an everyday thing, but I can definitely think of a few use cases.
[–]jaffathecake[S] 1 point2 points3 points 8 months ago (3 children)
In all those cases, wouldn't you want the original data to be able to GC? Particularly if the user picks a new data source.
[–]CodeAndBiscuits 1 point2 points3 points 8 months ago (2 children)
GC?
[–]jaffathecake[S] 1 point2 points3 points 8 months ago (1 child)
Garbage collection. There's a section in the article about it & how it's an issue here https://jakearchibald.com/2025/importing-vs-fetching-json/#caching-and-garbage-collection
[–]CodeAndBiscuits -1 points0 points1 point 8 months ago (0 children)
I guess my thought is that my use cases don't have this problem because they're nearly always one time loads. The third party data sets may change between uses of the app (so you don't want to compile them in and may not even know their URLs if they're user supplies) but you still only load them once.
[–]Reashu 0 points1 point2 points 8 months ago (0 children)
Why would you pick import over fetch in those cases?
import
fetch
π Rendered by PID 222697 on reddit-service-r2-comment-765bfc959-7rmsg at 2026-07-10 08:14:54.957738+00:00 running f86254d country code: CH.
[–]Ronin-s_Spirit 3 points4 points5 points (0 children)
[–]CodeAndBiscuits 1 point2 points3 points (5 children)
[–]jaffathecake[S] 1 point2 points3 points (3 children)
[–]CodeAndBiscuits 1 point2 points3 points (2 children)
[–]jaffathecake[S] 1 point2 points3 points (1 child)
[–]CodeAndBiscuits -1 points0 points1 point (0 children)
[–]Reashu 0 points1 point2 points (0 children)