optimal-img-format
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

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

Package Sidebar

Install

npm i optimal-img-format

Weekly Downloads

326

Version

1.4.0

License

UNLICENSE (HTTP://UNLICENSE.ORG/)

Unpacked Size

15.2 kB

Total Files

8

Last publish

Collaborators

  • lbb00