TLDR Dev · ARTICLES & TUTORIALS

IMPORTING VS FETCHING JSON

jakearchibald.com4 min read

Summary from the TLDR Dev newsletter

Using fetch() over the newly available JSON module imports in browsers is preferred as it has better error handling with response.status and the ability to access source text even when JSON parsing fails. The main concern with imported modules is that they are cached for the page's lifetime, creating memory leaks when importing dynamic data like search results, while fetch() allows garbage collection of unused data.