dynamic-import-no-cache
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

dynamic-import-no-cache

according to ECMAScript, the contents of dynamic imports are cached by default.

Any subsequent call to [import()] given the arguments referencingScriptOrModule and specifier, must return [...] a module which has already been evaluated

which means if you are using a dynamic import as part of your build process (eg. using chokidar to execute a function when a file is changed/added/deleted), then await import("/path/to/resource.js") will not fetch the updated version, rather the (cached) version that was fetched the first time that call was made.

dinc solves this by adding a cache busting timestamp param to the request, forcing node to fetch the fresh contents.

import dinc from "dynamic-import-no-cache";

const someResource = await dinc("/path/to/resource.js");

alternatively, if you don't want to install yet another node package, you can just do:

const someResource = await import(`/path/to/resource.js?${Date.now()}`);

Readme

Keywords

Package Sidebar

Install

npm i dynamic-import-no-cache

Weekly Downloads

2

Version

1.0.3

License

MIT

Unpacked Size

1.77 kB

Total Files

4

Last publish

Collaborators

  • paul-browne