[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"article-import-attributes-json-modules":44,"search-suggestions":257,"path-membership-import-attributes-json-modules":298,"related-import-attributes-json-modules":299,"code:js:true:kt5hme":424,"code:js:true:f91jhe":425,"code:js:true:14a6b4l":426,"code:plain:true:d6nw4d":427,"code:nginx:true:1o36gz1":428,"code:js:true:jx81wp":429,"comments-01a21cc5-7307-7177-ab2d-2bce87bb1416":430},[4,20,32],{"id":5,"slug":6,"name":7,"tagline":8,"description":9,"accentFrom":10,"accentTo":11,"icon":12,"defaultLocale":13,"locales":14,"features":16,"position":19},"019fe637-3d33-714b-b57f-23e163ffca0c","dev","Web Development","Read it. Run it. Prove it.","A post a day on modern web development — most with an editable playground and a quiz that explains every answer. Free, no account needed.","violet-500","cyan-400","◇","en",[13,15],"fa",{"courses":17,"paths":17,"articles":17,"exams":18,"flashcards":18,"packages":17,"community":17,"certificates":17,"teams":17,"commerce":17},true,false,0,{"id":21,"slug":22,"name":23,"tagline":24,"description":25,"accentFrom":26,"accentTo":10,"icon":27,"defaultLocale":13,"locales":28,"features":30,"position":31},"019fe637-3dc2-754c-8657-0f175bfee7c6","lang","Languages","Learn a language the way you learn a codebase.","Grammar explained the way good documentation explains an API — one idea at a time, each with a quiz.","amber-400","⌘",[13,15,29],"es",{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":17,"packages":18,"community":17,"certificates":17,"teams":18,"commerce":18},2,{"id":33,"slug":34,"name":35,"tagline":36,"description":37,"accentFrom":38,"accentTo":39,"icon":40,"defaultLocale":13,"locales":41,"features":42,"position":43},"7b3c16f2-931d-410e-802e-e1fa4edab7de","soft","Soft Skills","The half of the job nobody wrote documentation for.","Weekly, on the parts of working life that decide more than your code does — first weeks, meetings, interviews, promotions, and the people around you. Written from what actually happens, and recorded as a podcast you can listen to on the walk.","emerald-400","teal-300","◉",[13],{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":18,"packages":18,"community":17,"certificates":18,"teams":18,"commerce":18},3,{"id":45,"slug":46,"title":47,"subtitle":48,"excerpt":49,"coverUrl":50,"locale":13,"readingMinutes":51,"publishedAt":52,"viewCount":53,"likeCount":19,"commentCount":19,"author":54,"vertical":59,"topic":60,"tags":63,"_count":75,"playground":77,"body":79,"bodyMd":240,"seo":241,"translationGroupId":244,"series":48,"podcastUrl":48,"verticalId":5,"thread":245,"assessments":247,"translations":253,"quiz":255},"01a21cc5-7307-7177-ab2d-2bce87bb1416","import-attributes-json-modules","Your Static Host Can Silently Break Import Attributes",null,"`import config from '.\u002Fsettings.json' with { type: 'json' }` finally works natively in every major browser — no bundler, no fetch-then-parse dance. But it only works if your server sends the right `Content-Type` header. Get that wrong and the import throws, in production, while it works fine on your machine.","\u002Fmedia\u002Fcovers\u002Fimport-attributes-json-modules.png",6,"2026-12-03T06:42:15.569Z",29,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},"javascript","JavaScript",[64,66,69,72],{"slug":61,"name":65,"color":48},"Javascript",{"slug":67,"name":68,"color":48},"webdev","Webdev",{"slug":70,"name":71,"color":48},"tutorial","Tutorial",{"slug":73,"name":74,"color":48},"programming","Programming",{"assessments":76},1,{"slug":46,"title":78},"import attributes — interactive playground",{"blocks":80,"version":76},[81,85,88,91,97,100,104,107,110,114,117,120,123,126,129,132,136,139,143,146,149,152,155,159,162,165,168,171,176,179,182,185,190,194,197,200,203,206,209,212,215,218,221,224,227,230,233],{"id":82,"html":83,"type":84},"b1","\u003Cp>Your local dev server has been quietly lying to you.\u003C\u002Fp>","paragraph",{"id":86,"html":87,"type":84},"b2","\u003Cp>You write \u003Ccode>import config from &#39;.\u002Fsettings.json&#39; with { type: &#39;json&#39; };\u003C\u002Fcode>, run it locally, and it works — the object shows up, no bundler, no \u003Ccode>fetch\u003C\u002Fcode>, no \u003Ccode>JSON.parse\u003C\u002Fcode>. You ship it. Same code, same file, same browser. It throws.\u003C\u002Fp>",{"id":89,"html":90,"type":84},"b3","\u003Cp>Nothing in your diff changed. The only thing that&#39;s different is which server answered the request — and what header it decided to send back.\u003C\u002Fp>",{"id":92,"code":93,"type":94,"language":95,"highlight":96},"b4","\u002F\u002F works on your machine\nimport config from '.\u002Fsettings.json' with { type: 'json' };\nconsole.log(config.apiBase);","code","js",[],{"id":98,"html":99,"type":84},"b5","\u003Cp>This is a real, newly-usable browser feature — \u003Cstrong>import attributes\u003C\u002Fstrong> — and it comes with a gotcha specific enough that it will cost someone a deploy before they learn it from a blog post instead of a stack trace.\u003C\u002Fp>",{"id":101,"html":102,"text":102,"type":103,"level":31},"b6","What actually shipped","heading",{"id":105,"html":106,"type":84},"b7","\u003Cp>For as long as ES modules have existed, importing a JSON file meant one of three things: let your bundler&#39;s loader rewrite it into JS at build time, \u003Ccode>fetch()\u003C\u002Fcode> it and \u003Ccode>await res.json()\u003C\u002Fcode>, or — in Node — just \u003Ccode>require()\u003C\u002Fcode> it and hope you never ship that file over the network. There was no way to say &quot;this import is JSON&quot; directly in module syntax, because the module system had no concept of a non-JavaScript module at all.\u003C\u002Fp>",{"id":108,"html":109,"type":84},"b8","\u003Cp>\u003Cstrong>Import attributes\u003C\u002Fstrong> close that gap. You add a \u003Ccode>with { type: &#39;json&#39; }\u003C\u002Fcode> clause to the import, and the module loader treats the target as data, not code:\u003C\u002Fp>",{"id":111,"code":112,"type":94,"language":95,"highlight":113},"b9","\u002F\u002F static import\nimport config from '.\u002Fsettings.json' with { type: 'json' };\n\n\u002F\u002F dynamic import\nconst mod = await import('.\u002Fsettings.json', { with: { type: 'json' } });\nconsole.log(mod.default.apiBase);",[],{"id":115,"html":116,"type":84},"b10","\u003Cp>This is a Baseline \u003Cem>newly available\u003C\u002Fem> feature — it&#39;s been shipping in Chrome since version 123 (March 2024), and Firefox and Safari have since caught up, so all three engines understand the syntax today. &quot;Newly available&quot; is doing real work in that sentence, though: Baseline doesn&#39;t call this \u003Cem>widely\u003C\u002Fem> available until roughly 30 months of universal support have passed, which lands around late 2027. If any part of your audience is on an older point release, check before you rely on it as the only path.\u003C\u002Fp>",{"id":118,"html":119,"type":84},"b11","\u003C!-- playground:start -->",{"id":121,"html":122,"text":122,"type":103,"level":31},"b12","🎮 Try it yourself",{"id":124,"html":125,"type":84},"b13","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fimport-attributes-json-modules\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":127,"html":128,"type":84},"b14","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":130,"html":131,"type":84},"b15","\u003C!-- playground:end -->",{"id":133,"html":134,"text":135,"type":103,"level":31},"b16","The obvious fix that isn&#39;t one","The obvious fix that isn't one",{"id":137,"html":138,"type":84},"b17","\u003Cp>Say your import throws in production. The instinctive first move is to assume you wrote the import wrong, so you try variations:\u003C\u002Fp>",{"id":140,"code":141,"type":94,"language":95,"highlight":142},"b18","\u002F\u002F \"maybe I need the old syntax?\"\nimport config from '.\u002Fsettings.json' assert { type: 'json' };\n\n\u002F\u002F \"maybe I should destructure what I need?\"\nimport { apiBase } from '.\u002Fsettings.json' with { type: 'json' };",[],{"id":144,"html":145,"type":84},"b19","\u003Cp>Both are wrong, for different reasons, and neither error message tells you the actual problem.\u003C\u002Fp>",{"id":147,"html":148,"type":84},"b20","\u003Cp>\u003Ccode>assert { type: &#39;json&#39; }\u003C\u002Fcode> is the \u003Cem>previous\u003C\u002Fem> version of this proposal. MDN now documents it as non-standard — the syntax moved from \u003Ccode>assert\u003C\u002Fcode> to \u003Ccode>with\u003C\u002Fcode> as the feature advanced through standardization, and engines are converging on \u003Ccode>with\u003C\u002Fcode> as the only one that keeps working. If a tutorial you&#39;re reading uses \u003Ccode>assert\u003C\u002Fcode>, it predates the rename.\u003C\u002Fp>",{"id":150,"html":151,"type":84},"b21","\u003Cp>The named import is wrong for a completely different reason that has nothing to do with syntax age: \u003Cstrong>JSON modules only ever have a default export.\u003C\u002Fstrong> There is no mechanism for turning top-level JSON keys into named bindings — a JSON document doesn&#39;t have &quot;exports,&quot; it has one value, and that value is what \u003Ccode>import config from …\u003C\u002Fcode> binds to. \u003Ccode>import { apiBase } from …\u003C\u002Fcode> isn&#39;t almost-right. It&#39;s not a thing the spec defines, for any version of the syntax.\u003C\u002Fp>",{"id":153,"html":154,"type":84},"b22","\u003Cp>Neither of those was the actual bug, though. The actual bug was never in the import statement at all.\u003C\u002Fp>",{"id":156,"html":157,"text":158,"type":103,"level":31},"b23","The real diagnosis: the browser doesn&#39;t trust your file extension","The real diagnosis: the browser doesn't trust your file extension",{"id":160,"html":161,"type":84},"b24","\u003Cp>Here&#39;s the part that matters more than the syntax: \u003Cstrong>a browser does not decide a response is JSON because the URL ends in \u003Ccode>.json\u003C\u002Fcode>.\u003C\u002Fstrong> It decides based on one thing — the \u003Ccode>Content-Type\u003C\u002Fcode> header the server actually sent back with the response.\u003C\u002Fp>",{"id":163,"html":164,"type":84},"b25","\u003Cp>Your local dev server (Vite, the Next.js dev server, \u003Ccode>http-server\u003C\u002Fcode>, whatever) almost certainly serves \u003Ccode>.json\u003C\u002Fcode> files with \u003Ccode>Content-Type: application\u002Fjson\u003C\u002Fcode> out of the box, because its MIME-type table knows the extension. That&#39;s why it works locally without you ever thinking about it.\u003C\u002Fp>",{"id":166,"html":167,"type":84},"b26","\u003Cp>Plenty of production hosts don&#39;t make that same choice as reliably. A plain static file server with an incomplete or custom MIME map, an S3-style bucket where metadata was set by whatever uploaded the file, a reverse proxy with a \u003Ccode>default_type\u003C\u002Fcode> fallback — any of these can hand back \u003Ccode>text\u002Fplain\u003C\u002Fcode>, \u003Ccode>application\u002Foctet-stream\u003C\u002Fcode>, or nothing at all for a \u003Ccode>.json\u003C\u002Fcode> file, and still serve the \u003Cem>bytes\u003C\u002Fem> correctly. Your file is fine. Your JSON is valid. The header lies about what it is, and the module loader takes the header&#39;s word over the filename&#39;s.\u003C\u002Fp>",{"id":169,"html":170,"type":84},"b27","\u003Cp>Open your browser&#39;s network tab, request the same \u003Ccode>.json\u003C\u002Fcode> file from your production host, and check the response headers. If \u003Ccode>Content-Type\u003C\u002Fcode> isn&#39;t a JSON type — \u003Ccode>application\u002Fjson\u003C\u002Fcode>, or anything ending in \u003Ccode>+json\u003C\u002Fcode> — that import was never going to succeed there, no matter how you spelled the import statement.\u003C\u002Fp>",{"id":172,"code":173,"type":94,"language":174,"highlight":175},"b28","# this response makes the import throw, regardless of the file's actual contents\nHTTP\u002F1.1 200 OK\nContent-Type: text\u002Fplain","plain",[],{"id":177,"html":178,"type":84},"b29","\u003Cp>The check is strict on purpose. It&#39;s the same philosophy that already governs \u003Ccode>&lt;script type=&quot;module&quot;&gt;\u003C\u002Fcode>: browsers will not execute a response as a module unless the server explicitly labels it correctly, because a lenient content-sniffing rule for \u003Cem>executable\u003C\u002Fem> content is a script-injection vector waiting to happen. JSON modules inherited that same strictness even though JSON itself can&#39;t execute anything — consistency won over convenience here, and once you know that&#39;s the tradeoff, the error stops being mysterious.\u003C\u002Fp>",{"id":180,"html":181,"text":181,"type":103,"level":31},"b30","The fix",{"id":183,"html":184,"type":84},"b31","\u003Cp>There&#39;s no workaround in the import statement, because the import statement was never the problem. The fix lives entirely in server configuration: make sure whatever serves your JSON file sends a JSON \u003Ccode>Content-Type\u003C\u002Fcode>.\u003C\u002Fp>",{"id":186,"code":187,"type":94,"language":188,"highlight":189},"b32","# nginx: make sure .json has an explicit, correct type\nlocation ~ \\.json$ {\n  default_type application\u002Fjson;\n}","nginx",[],{"id":191,"code":192,"type":94,"language":95,"highlight":193},"b33","\u002F\u002F Node static-file servers: the `mime`\u002F`mime-types` package usually\n\u002F\u002F already maps .json correctly — the bug is almost always a custom\n\u002F\u002F static handler that skips it, or an object-storage upload that\n\u002F\u002F never set metadata at all.\nres.setHeader('Content-Type', 'application\u002Fjson');",[],{"id":195,"html":196,"type":84},"b34","\u003Cp>Once the header is right, the same import statement that threw in production works identically to how it worked on your machine — because now, for the first time, the two environments are actually answering the same question the same way.\u003C\u002Fp>",{"id":198,"html":199,"text":199,"type":103,"level":31},"b35","What to check before you ship this",{"id":201,"html":202,"type":84},"b36","\u003Cp>If you&#39;re adopting import attributes for the first time, don&#39;t just test the import locally and call it done — that&#39;s testing against the one server in the whole chain that was never going to lie to you. Check the response headers your \u003Cem>production\u003C\u002Fem> host sends for the exact files you&#39;re importing, on the exact path readers will hit. It&#39;s a thirty-second check in the network tab that replaces a very confusing on-call page.\u003C\u002Fp>",{"id":204,"html":205,"type":84},"b37","\u003Cp>And when you do reach for this, remember the shape of what you&#39;re allowed to get back: one default export, nothing named, and only if the server agrees with the file extension. Get the header right and this finally kills the \u003Ccode>fetch\u003C\u002Fcode>-then-\u003Ccode>JSON.parse\u003C\u002Fcode> dance for static config and data files — no bundler required.\u003C\u002Fp>",{"id":207,"html":208,"type":84},"b38","\u003C!-- quiz:start -->",{"id":210,"html":211,"text":211,"type":103,"level":31},"b39","🧠 Test yourself",{"id":213,"html":214,"type":84},"b40","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fimport-attributes-json-modules\u002Fquiz\">Take the 8-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":216,"html":217,"type":84},"b41","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":219,"html":220,"type":84},"b42","\u003C!-- quiz:end -->",{"id":222,"html":223,"type":84},"b43","\u003Cp>Have you checked what \u003Ccode>Content-Type\u003C\u002Fcode> your own static host actually sends for a \u003Ccode>.json\u003C\u002Fcode> file? Open the network tab before you find out the hard way.\u003C\u002Fp>",{"id":225,"type":226},"b44","divider",{"id":228,"html":229,"type":84},"b45","\u003Cp>🚀 \u003Cstrong>Want more like this?\u003C\u002Fstrong> Every guide, playground, and quiz lives on \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">bestpractic.org\u003C\u002Fa>\u003C\u002Fstrong> — open it and \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">sign up free\u003C\u002Fa>\u003C\u002Fstrong> so the next one finds you.\u003C\u002Fp>",{"id":231,"html":232,"type":84},"b46","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":234,"type":235,"items":236,"ordered":18},"b47","list",[237,238,239],"⭐ \u003Cstrong>GitHub\u003C\u002Fstrong> — follow me and star the projects: \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fparsajiravand\">github.com\u002Fparsajiravand\u003C\u002Fa>","💬 \u003Cstrong>Discord\u003C\u002Fstrong> — join the frontend best-practices community: \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ\">discord.gg\u002Fd9KRhuAwQ\u003C\u002Fa>","📸 \u003Cstrong>Instagram\u003C\u002Fstrong> — frontend best practices, daily: \u003Ca href=\"https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F\">@bestpractice___\u003C\u002Fa>","Your local dev server has been quietly lying to you.\n\nYou write `import config from '.\u002Fsettings.json' with { type: 'json' };`, run it locally, and it works — the object shows up, no bundler, no `fetch`, no `JSON.parse`. You ship it. Same code, same file, same browser. It throws.\n\nNothing in your diff changed. The only thing that's different is which server answered the request — and what header it decided to send back.\n\n```js\n\u002F\u002F works on your machine\nimport config from '.\u002Fsettings.json' with { type: 'json' };\nconsole.log(config.apiBase);\n```\n\nThis is a real, newly-usable browser feature — **import attributes** — and it comes with a gotcha specific enough that it will cost someone a deploy before they learn it from a blog post instead of a stack trace.\n\n## What actually shipped\n\nFor as long as ES modules have existed, importing a JSON file meant one of three things: let your bundler's loader rewrite it into JS at build time, `fetch()` it and `await res.json()`, or — in Node — just `require()` it and hope you never ship that file over the network. There was no way to say \"this import is JSON\" directly in module syntax, because the module system had no concept of a non-JavaScript module at all.\n\n**Import attributes** close that gap. You add a `with { type: 'json' }` clause to the import, and the module loader treats the target as data, not code:\n\n```js\n\u002F\u002F static import\nimport config from '.\u002Fsettings.json' with { type: 'json' };\n\n\u002F\u002F dynamic import\nconst mod = await import('.\u002Fsettings.json', { with: { type: 'json' } });\nconsole.log(mod.default.apiBase);\n```\n\nThis is a Baseline *newly available* feature — it's been shipping in Chrome since version 123 (March 2024), and Firefox and Safari have since caught up, so all three engines understand the syntax today. \"Newly available\" is doing real work in that sentence, though: Baseline doesn't call this *widely* available until roughly 30 months of universal support have passed, which lands around late 2027. If any part of your audience is on an older point release, check before you rely on it as the only path.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fimport-attributes-json-modules\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n## The obvious fix that isn't one\n\nSay your import throws in production. The instinctive first move is to assume you wrote the import wrong, so you try variations:\n\n```js\n\u002F\u002F \"maybe I need the old syntax?\"\nimport config from '.\u002Fsettings.json' assert { type: 'json' };\n\n\u002F\u002F \"maybe I should destructure what I need?\"\nimport { apiBase } from '.\u002Fsettings.json' with { type: 'json' };\n```\n\nBoth are wrong, for different reasons, and neither error message tells you the actual problem.\n\n`assert { type: 'json' }` is the *previous* version of this proposal. MDN now documents it as non-standard — the syntax moved from `assert` to `with` as the feature advanced through standardization, and engines are converging on `with` as the only one that keeps working. If a tutorial you're reading uses `assert`, it predates the rename.\n\nThe named import is wrong for a completely different reason that has nothing to do with syntax age: **JSON modules only ever have a default export.** There is no mechanism for turning top-level JSON keys into named bindings — a JSON document doesn't have \"exports,\" it has one value, and that value is what `import config from …` binds to. `import { apiBase } from …` isn't almost-right. It's not a thing the spec defines, for any version of the syntax.\n\nNeither of those was the actual bug, though. The actual bug was never in the import statement at all.\n\n## The real diagnosis: the browser doesn't trust your file extension\n\nHere's the part that matters more than the syntax: **a browser does not decide a response is JSON because the URL ends in `.json`.** It decides based on one thing — the `Content-Type` header the server actually sent back with the response.\n\nYour local dev server (Vite, the Next.js dev server, `http-server`, whatever) almost certainly serves `.json` files with `Content-Type: application\u002Fjson` out of the box, because its MIME-type table knows the extension. That's why it works locally without you ever thinking about it.\n\nPlenty of production hosts don't make that same choice as reliably. A plain static file server with an incomplete or custom MIME map, an S3-style bucket where metadata was set by whatever uploaded the file, a reverse proxy with a `default_type` fallback — any of these can hand back `text\u002Fplain`, `application\u002Foctet-stream`, or nothing at all for a `.json` file, and still serve the *bytes* correctly. Your file is fine. Your JSON is valid. The header lies about what it is, and the module loader takes the header's word over the filename's.\n\nOpen your browser's network tab, request the same `.json` file from your production host, and check the response headers. If `Content-Type` isn't a JSON type — `application\u002Fjson`, or anything ending in `+json` — that import was never going to succeed there, no matter how you spelled the import statement.\n\n```\n# this response makes the import throw, regardless of the file's actual contents\nHTTP\u002F1.1 200 OK\nContent-Type: text\u002Fplain\n```\n\nThe check is strict on purpose. It's the same philosophy that already governs `\u003Cscript type=\"module\">`: browsers will not execute a response as a module unless the server explicitly labels it correctly, because a lenient content-sniffing rule for *executable* content is a script-injection vector waiting to happen. JSON modules inherited that same strictness even though JSON itself can't execute anything — consistency won over convenience here, and once you know that's the tradeoff, the error stops being mysterious.\n\n## The fix\n\nThere's no workaround in the import statement, because the import statement was never the problem. The fix lives entirely in server configuration: make sure whatever serves your JSON file sends a JSON `Content-Type`.\n\n```nginx\n# nginx: make sure .json has an explicit, correct type\nlocation ~ \\.json$ {\n  default_type application\u002Fjson;\n}\n```\n\n```js\n\u002F\u002F Node static-file servers: the `mime`\u002F`mime-types` package usually\n\u002F\u002F already maps .json correctly — the bug is almost always a custom\n\u002F\u002F static handler that skips it, or an object-storage upload that\n\u002F\u002F never set metadata at all.\nres.setHeader('Content-Type', 'application\u002Fjson');\n```\n\nOnce the header is right, the same import statement that threw in production works identically to how it worked on your machine — because now, for the first time, the two environments are actually answering the same question the same way.\n\n## What to check before you ship this\n\nIf you're adopting import attributes for the first time, don't just test the import locally and call it done — that's testing against the one server in the whole chain that was never going to lie to you. Check the response headers your *production* host sends for the exact files you're importing, on the exact path readers will hit. It's a thirty-second check in the network tab that replaces a very confusing on-call page.\n\nAnd when you do reach for this, remember the shape of what you're allowed to get back: one default export, nothing named, and only if the server agrees with the file extension. Get the header right and this finally kills the `fetch`-then-`JSON.parse` dance for static config and data files — no bundler required.\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 8-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fimport-attributes-json-modules\u002Fquiz)**\n\n_Instant feedback, a hint on every question, and an explanation for each answer — right or wrong._\n\n\u003C!-- quiz:end -->\n\nHave you checked what `Content-Type` your own static host actually sends for a `.json` file? Open the network tab before you find out the hard way.\n\n---\n\n🚀 **Want more like this?** Every guide, playground, and quiz lives on **[bestpractic.org](https:\u002F\u002Fbestpractic.org\u002F)** — open it and **[sign up free](https:\u002F\u002Fbestpractic.org\u002F)** so the next one finds you.\n\n*Thanks for reading! Let's stay connected:*\n\n- ⭐ **GitHub** — follow me and star the projects: [github.com\u002Fparsajiravand](https:\u002F\u002Fgithub.com\u002Fparsajiravand)\n- 💬 **Discord** — join the frontend best-practices community: [discord.gg\u002Fd9KRhuAwQ](https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ)\n- 📸 **Instagram** — frontend best practices, daily: [@bestpractice___](https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F)",{"title":47,"canonical":242,"description":243},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fimport-attributes-json-modules","`import config from '.\u002Fsettings.json' with { type: 'json' }` finally works natively in every major browser — no bundler, no fetch-then-parse dance. But it only works if your server","01a21cc5-7307-7177-ab2d-2f30ebc95b4a",{"id":246,"locked":18},"01a21cc5-7321-75f9-9133-9a298089ae30",[248],{"id":249,"slug":46,"title":250,"_count":251},"01a21cc5-733a-71ed-879c-c0a87cf2b0d7","Import Attributes & JSON Modules",{"questions":252},8,[254],{"locale":13,"slug":46},{"id":249,"slug":46,"title":250,"_count":256,"questionCount":252},{"questions":252},[258,260,262,266,268,272,276,280,282,286,290,294],{"slug":67,"name":68,"articles":259},202,{"slug":61,"name":65,"articles":261},159,{"slug":263,"name":264,"articles":265},"frontend","Frontend",105,{"slug":70,"name":71,"articles":267},91,{"slug":269,"name":270,"articles":271},"css","Css",59,{"slug":273,"name":274,"articles":275},"typescript","Typescript",37,{"slug":277,"name":278,"articles":279},"performance","Performance",34,{"slug":73,"name":74,"articles":281},27,{"slug":283,"name":284,"articles":285},"react","React",23,{"slug":287,"name":288,"articles":289},"node","Node",19,{"slug":291,"name":292,"articles":293},"browser","Browser",18,{"slug":295,"name":296,"articles":297},"nextjs","Nextjs",14,[],{"items":300,"meta":423},[301,313,331,350,368,386,404],{"id":45,"slug":46,"title":47,"subtitle":48,"excerpt":49,"coverUrl":50,"locale":13,"readingMinutes":51,"publishedAt":52,"viewCount":302,"likeCount":19,"commentCount":19,"author":303,"vertical":304,"topic":305,"tags":306,"_count":311,"playground":312,"hasQuiz":17,"hasPlayground":17},30,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[307,308,309,310],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"slug":73,"name":74,"color":48},{"assessments":76},{"slug":46},{"id":314,"slug":315,"title":316,"subtitle":48,"excerpt":317,"coverUrl":318,"locale":13,"readingMinutes":319,"publishedAt":320,"viewCount":267,"likeCount":19,"commentCount":19,"author":321,"vertical":322,"topic":323,"tags":324,"_count":329,"playground":330,"hasQuiz":17,"hasPlayground":17},"01a21cc5-6a9e-740d-b36d-cfa2c70b74e2","resizable-arraybuffer-transfer","I Kept Copying Buffers to Grow Them. Resizable ArrayBuffer Fixed It.","Every \"growable buffer\" helper allocates bigger, copies everything in, and throws the old buffer away — on a 200MB export that copy is a visible stutter. Resizable ArrayBuffer grows in place, and transfer() hands off ownership without a copy or a postMessage side effect.","\u002Fmedia\u002Fcovers\u002Fresizable-arraybuffer-transfer.png",7,"2026-12-02T12:03:44.541Z",{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[325,326,327,328],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":277,"name":278,"color":48},{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":315},{"id":332,"slug":333,"title":334,"subtitle":48,"excerpt":335,"coverUrl":336,"locale":13,"readingMinutes":51,"publishedAt":337,"viewCount":338,"likeCount":19,"commentCount":19,"author":339,"vertical":340,"topic":341,"tags":343,"_count":348,"playground":349,"hasQuiz":17,"hasPlayground":17},"01a21cc5-7d63-76c4-94d1-bdb6902fadbe","typescript-const-type-parameters","I Stopped Asking Callers for `as const`. Const Type Parameters Do It.","A generic helper only keeps its literal types if every caller remembers to tack `as const` onto the argument — forget once and it silently widens. TypeScript's const type parameters infer the literal type automatically, with no cooperation from the caller required.","\u002Fmedia\u002Fcovers\u002Ftypescript-const-type-parameters.png","2026-12-01T04:21:15.823Z",145,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":273,"name":342},"TypeScript",[344,345,346,347],{"slug":273,"name":274,"color":48},{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":333},{"id":351,"slug":352,"title":353,"subtitle":48,"excerpt":354,"coverUrl":355,"locale":13,"readingMinutes":51,"publishedAt":356,"viewCount":357,"likeCount":19,"commentCount":19,"author":358,"vertical":359,"topic":360,"tags":361,"_count":366,"playground":367,"hasQuiz":17,"hasPlayground":17},"01a1fce0-de91-712e-bc98-72dba2b10bf5","react-use-api-promises-context","`use()` Breaks the Rules of Hooks on Purpose. Here's the Catch.","React's `use()` reads a promise or context mid-render and skips the Rules of Hooks on purpose — but that same freedom hides a caching trap that resuspends your component forever if you miss it.","\u002Fmedia\u002Fcovers\u002Freact-use-api-promises-context.png","2026-11-27T11:49:31.813Z",296,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":283,"name":284},[362,363,364,365],{"slug":283,"name":284,"color":48},{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":263,"name":264,"color":48},{"assessments":76},{"slug":352},{"id":369,"slug":370,"title":371,"subtitle":48,"excerpt":372,"coverUrl":373,"locale":13,"readingMinutes":51,"publishedAt":374,"viewCount":375,"likeCount":19,"commentCount":19,"author":376,"vertical":377,"topic":378,"tags":379,"_count":384,"playground":385,"hasQuiz":17,"hasPlayground":17},"01a1fce0-dac8-71e2-bd25-94b1cc5aa337","typescript-template-literal-types","Template Literal Types Explained: Catching Path Typos at Compile Time","A typo'd dot-path like \"theme.colros.primary\" compiles clean and fails silently at runtime — template literal types make TypeScript catch it before you ship.","\u002Fmedia\u002Fcovers\u002Ftypescript-template-literal-types.png","2026-11-27T11:49:01.332Z",259,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":273,"name":342},[380,381,382,383],{"slug":273,"name":274,"color":48},{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"assessments":76},{"slug":370},{"id":387,"slug":388,"title":389,"subtitle":48,"excerpt":390,"coverUrl":391,"locale":13,"readingMinutes":319,"publishedAt":392,"viewCount":393,"likeCount":19,"commentCount":19,"author":394,"vertical":395,"topic":396,"tags":397,"_count":402,"playground":403,"hasQuiz":17,"hasPlayground":17},"01a1fce0-d4f1-7184-bf57-f7ad669d6255","websocket-reconnect-exponential-backoff","Your WebSocket Reconnects Fine. The Messages It Missed Never Do.","Exponential backoff fixes the reconnect storm. It does nothing for the messages your server sent while the socket was down — those need an app-level replay, or they're gone for good.","\u002Fmedia\u002Fcovers\u002Fwebsocket-reconnect-exponential-backoff.png","2026-11-27T11:48:00.443Z",256,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":61,"name":62},[398,399,400,401],{"slug":61,"name":65,"color":48},{"slug":67,"name":68,"color":48},{"slug":73,"name":74,"color":48},{"slug":263,"name":264,"color":48},{"assessments":76},{"slug":388},{"id":405,"slug":406,"title":407,"subtitle":48,"excerpt":408,"coverUrl":409,"locale":13,"readingMinutes":410,"publishedAt":411,"viewCount":412,"likeCount":19,"commentCount":19,"author":413,"vertical":414,"topic":415,"tags":416,"_count":421,"playground":422,"hasQuiz":17,"hasPlayground":17},"01a1fce0-ce76-7424-b4da-6db21c69992c","nextjs-weekly-use-cache-remote-vs-private","Next.js 16 use cache: remote vs use cache: private","Next.js 16's use cache: remote shares a cache across instances; use cache: private never leaves one request. Which to pick, plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Fnextjs-weekly-use-cache-remote-vs-private.png",16,"2026-11-27T11:47:29.944Z",254,{"id":55,"name":56,"username":57,"avatarUrl":48,"headline":58},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":295,"name":296},[417,418,419,420],{"slug":295,"name":296,"color":48},{"slug":67,"name":68,"color":48},{"slug":70,"name":71,"color":48},{"slug":61,"name":65,"color":48},{"assessments":76},{"slug":406},{"page":76,"perPage":319,"total":261,"totalPages":285},"\u003Cdiv class=\"shj shj-lang-js shj-multiline\" data-lang=\"js\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-cmnt\">\u002F\u002F works on your machine\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">import\u003C\u002Fspan> config \u003Cspan class=\"shj-kwd\">from\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'.\u002Fsettings.json'\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">with\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> type\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'json'\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\nconsole\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">log\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>config\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>apiBase\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-js shj-multiline\" data-lang=\"js\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-cmnt\">\u002F\u002F static import\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">import\u003C\u002Fspan> config \u003Cspan class=\"shj-kwd\">from\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'.\u002Fsettings.json'\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">with\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> type\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'json'\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F dynamic import\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> mod \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">await\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">import\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">'.\u002Fsettings.json'\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> with\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> type\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'json'\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\nconsole\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">log\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>mod\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">default\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>apiBase\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-js shj-multiline\" data-lang=\"js\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-cmnt\">\u002F\u002F \"maybe I need the old syntax?\"\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">import\u003C\u002Fspan> config \u003Cspan class=\"shj-kwd\">from\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'.\u002Fsettings.json'\u003C\u002Fspan> assert \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> type\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'json'\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F \"maybe I should destructure what I need?\"\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">import\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> apiBase \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">from\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'.\u002Fsettings.json'\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">with\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> type\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'json'\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>;\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-plain shj-multiline\" data-lang=\"plain\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\"># this response makes the import throw, regardless of the file's actual contents\nHTTP\u002F1.1 200 OK\nContent-Type: text\u002Fplain\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-nginx shj-multiline\" data-lang=\"nginx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\"># nginx: make sure .json has an explicit, correct type\nlocation ~ \\.json$ {\n  default_type application\u002Fjson;\n}\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-js shj-multiline\" data-lang=\"js\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-cmnt\">\u002F\u002F Node static-file servers: the `mime`\u002F`mime-types` package usually\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F already maps .json correctly — the bug is almost always a custom\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F static handler that skips it, or an object-storage upload that\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F never set metadata at all.\n\u003C\u002Fspan>res\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">setHeader\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">'Content-Type'\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-str\">'application\u002Fjson'\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>",{"locked":18,"total":19,"comments":431},[]]