Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

tw-image-metrics

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tw-image-metrics

Scrapes a page to gather performance metrics about loaded images.

latest
npmnpm
Version
1.1.0
Version published
Maintainers
1
Created
Source

tw-image-metrics

Scrapes a page to gather performance metrics about loaded images.

Usage

You must pass a valid window object for the page you wish to scrape.

var imageMetrics = require('tw-image-metrics');
var data = imageMetrics(window);

Optionally, you can also pass an array of filetypes to filter by.

var pngsOnly = imageMetrics(window, ['png']);

Result

tw-image-metrics returns an array of objects with performance data for each image.

[{
  url: "https://foo.bar/image.png",
  type: "png",
  size: 123.45,
  loadTime: 250,
  width: 1024,
  height: 768,
  from: "css"
}]

url: the full URL of the image.

type: The filetype of the image.

size: The filesize of the image (in kilobytes).

loadTime: The time it took to load the image (in milliseconds).

width: The width of the image (in pixels).

height: The height of the image (in pixels).

from: The source of the image. Typically, this is img for images loaded from HTML, and css for images loaded from CSS.

Notes

tw-image-metrics may return 0 for the size property if the image is loaded from the cache. Make sure your cache is clear before calling this function.

FAQs

Package last updated on 05 Jun 2019

Did you know?

Socket

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.

Install

Related posts