UtilitiespreloadImage

preloadImage

Preloads an image from a URL.

Installation

npm install @madeinhaus/utils

Import

import { preloadImage } from '@madeinhaus/utils';

Parameters

  • url (string): The URL of the image to preload.

Returns

  • (Promise<HTMLImageElement>): A promise that resolves with the preloaded image.

Usage

import { preloadImage } from '@madeinhaus/utils';
 
async function loadImage() {
  const url = 'https://example.com/image.jpg';
  const image = await preloadImage(url);
  console.log('Image loaded:', image);
}

In this example, we import the preloadImage function from the @madeinhaus/utils package and use it to preload an image from a URL.