Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
img info snippet sort by multiple props
  • Loading branch information
jhadev committed May 24, 2022
commit 9e8ff9847a5fd7d4a04de3894bb41acc413d1dec
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,44 @@ function findATFLazyLoadedImages() {

console.log(findATFLazyLoadedImages());

```

### Image Info

List all image resources and sort by (`name, transferSize, encodedBodySize, decodedBodySize, initiatorType`)

[More Info](https://developer.mozilla.org/en-US/docs/Web/API/PerformanceResourceTiming])

```js
function getImgs(sortBy) {
const imgs = [];

const resourceListEntries = performance.getEntriesByType("resource");
resourceListEntries.forEach(
({
name,
transferSize,
encodedBodySize,
decodedBodySize,
initiatorType,
}) => {
if (initiatorType == "img") {
imgs.push({
name,
transferSize,
decodedBodySize,
encodedBodySize,
});
}
}
);

const imgList = imgs.sort((a, b) => {
return b[sortBy] - a[sortBy];
});

return imgList
}
console.log(getImgs('encodedBodySize'))

```