
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
image-promise
Advanced tools
Load an image and return a promise in the browser, in 0.4KB, no dependencies
npm install --save image-promise
import loadImage, {unload as unloadImage} from 'image-promise';
If you don't use node/babel, include this:
<script src="dist/image-promise.browser.js"></script>
It uses the ES2015 window.Promise
, so if you need to support older browsers you need a polyfill.
You can load a single image from its URL:
loadImage('img.jpg').then(function (img) {
console.log('Image loaded!', img);
}).catch(function () {
console.error('Image failed to load :(');
});
image-promise
also caches the generated <img>
tags so successive calls with the same exact src
string will return the same <img>
tag and be resolve at the same time as the first one.
Because are <img>
are cached internally, if you want to uncache and unload them from memory, call the unload
method on the same src
:
loadImage.unload('img.jpg');
// or, if you use ES2015:
unloadImage('img.jpg')
None! But you might need to polyfill window.Promise
MIT © Federico Brigante
FAQs
Load one or more images, return a promise. Only 0.4KB, for the browser, no dependencies.
The npm package image-promise receives a total of 5,547 weekly downloads. As such, image-promise popularity was classified as popular.
We found that image-promise demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.