New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dynamic-import-no-cache

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dynamic-import-no-cache

dynamic import with no caching

latest
npmnpm
Version
1.0.3
Version published
Weekly downloads
2
100%
Maintainers
1
Weekly downloads
 
Created
Source

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()}`);

Keywords

dynamic

FAQs

Package last updated on 04 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts