PostHTML plugin that fetches remote or local content and interpolates it into HTML using posthtml-expressions. Current stable version: 4.0.3. Release cadence is irregular; the plugin is mature and stable. Key differentiators: simple declarative <fetch> tag, supports JSON and text responses, integrates with PostHTML ecosystem, uses ofetch under the hood for HTTP, and allows configuration of tag names, URL attribute, and expression options. It is designed for server-side rendering and build-time content injection, not for dynamic client-side fetching.
npm install posthtml-fetchNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage: posthtml-fetch fetches a remote JSON API and interpolates response fields into HTML using mustache-like expressions.
Upgrade without code changes but test for subtle differences in HTTP handling (e.g., error messages, redirect behavior).
Use 'attribute' instead of 'attr' when passing options.
Ensure the URL returns JSON or text; or use posthtml-expressions to transform the response manually.
Pass tags: ['myTag'] if you want to use a different tag name.
Set preserveTag: false (default) to remove the tag after interpolation.
Run 'npm install ofetch' alongside posthtml-fetch.
Use default import: import posthtmlFetch from 'posthtml-fetch'
Use import() dynamic import or switch to ESM ("type": "module" in package.json). For CommonJS, use const posthtmlFetch = require('posthtml-fetch').default or enable esModuleInterop.Rename 'attr' to 'attribute' in the options passed to posthtmlFetch().