1.4.0 • Published 5 months ago

optimal-img-format v1.4.0

Weekly downloads
-
License
UNLICENSE (HTTP:/...
Repository
github
Last release
5 months ago

optimal-img-format

Npm Bundlephobia Coverage Typescript License Npm download

Get optimal image format on the browser and server.

  • Support for AVIF, WebP and JPEG XL
  • Zero dependency
  • Fast, using promise singleton and cache for detecting

Online demo

Usage

Install

npm install optimal-img-format

Formats

Formats refer to the subtypes of the MIME type images/*.

  • jxl
  • avif
  • webp

Browser

import {
  getOptimalImgFormatOnBrowser,
  isSupportWebP,
} from "optimal-img-format";

const format = await getOptimalImgFormatOnBrowser(["avif", "webp"]);
const formatWebp = await isSupportWebP();

Detecting browser supports by:

Server

import {
  getOptimalImgFormatByAccept,
  getOptimalImgFormatByAgent,
} from "optimal-img-format";

const format =
  getOptimalImgFormatByAccept(request.headers.accept, ["avif", "webp"]) ||
  getOptimalImgFormatByAgent(request.headers.agent, ["avif", "webp"]);

Changelog

CHANGELOG

Contributions

If you have any suggestions for this project or discover a bug, please raise an Issue.

License

UNLICENSE

1.4.0

5 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.2.0

5 months ago

1.1.0

5 months ago

1.0.0

5 months ago