
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
browser-preloader
Advanced tools
Preload resources in browser, e.g: images.
npm install browser-preloader
yarn add browser-preloader
pnpm add browser-preloader
import { preloadImages } from 'browser-preloader'
// Basic usage
const loadedImages = await preloadImages(['foo.jpg', 'bar.png'])
console.log(`Loaded ${loadedImages.length} images`)
// With callbacks
preloadImages(['foo.jpg', 'bar.png'], {
timeout: 5000,
onProgress(loaded, total) {
console.log(`Progress: ${loaded}/${total}`)
},
onComplete(images) {
console.log(`Successfully loaded: ${images.length}`)
},
onError(err, url) {
console.log(`Image ${url} failed to load`, err)
},
})
// Load images when browser is idle
preloadImages(['foo.jpg', 'bar.png'], {
loadOnIdle: true,
idleTimeout: 2000,
})
// Sequential loading with limited concurrency
preloadImages(['foo.jpg', 'bar.png', 'baz.jpg'], {
strategy: 'sequential',
maxConcurrent: 2,
})
// With cross-origin support
preloadImages(['https://example.com/image.jpg'], {
crossOrigin: true,
crossOriginAttribute: 'anonymous',
})
(images: string | string[], options: PreloadImagesOptions = {}) => Promise<HTMLImageElement[]>Preload images in browser.
string | string[]Array of image URLs or a single image URL.
PreloadImagesOptionsfalseOptions for preloading images, see PreloadImagesOptions in Interfaces.
/**
* Options for the {@link preloadImages} function
*/
export interface PreloadImagesOptions {
/**
* Whether to set the cross-origin attribute on the image
*
* @default false
*/
crossOrigin?: boolean
/**
* The cross-origin attribute to use for the image
*
* @default `anonymous`
*/
crossOriginAttribute?: 'anonymous' | 'use-credentials'
/**
* Timeout for requestIdleCallback in milliseconds
* Only effective when loadOnIdle is true
*
* @default 2000
*/
idleTimeout?: number
/**
* Whether to load images only when browser is idle
* Uses requestIdleCallback API if available
*
* @default false
*/
loadOnIdle?: boolean
/**
* Maximum number of concurrent image loads
*
* @default 6
*/
maxConcurrent?: number
/**
* The strategy to load images
*
* @default `parallel`
*/
strategy?: 'parallel' | 'sequential'
/**
* Timeout for image loading in milliseconds
*
* @default 0
*/
timeout?: number
/**
* Callback function to be called when all images are loaded
* @param loadedImages - Array of loaded HTMLImageElement objects
*/
onComplete?: (loadedImages: HTMLImageElement[]) => void
/**
* Callback function to be called when an error occurs
* @param error - Error object
* @param url - The URL of the image that failed to load
*/
onError?: (error: Error, url: string) => void
/**
* Callback function to be called when the progress of image loading changes
*
* @param loadedCount - Number of images loaded so far
* @param totalCount - Total number of images to be loaded
*/
onProgress?: (loadedCount: number, totalCount: number) => void
}
FAQs
Preload resources in browser, e.g: images.
We found that browser-preloader 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
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.