tw-image-metrics
v1.1.0
Published
Scrapes a page to gather performance metrics about loaded images.
Downloads
6
Readme
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.