Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Add asset hitrate #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add asset hitrate #32

wants to merge 3 commits into from

Conversation

omrilotan
Copy link
Member

@omrilotan omrilotan commented Mar 1, 2021

  • Bug fix
  • New feature
  • Breaking change
  • Deprecations
  • Tests added
  • Doc added

cachehit

Get resource browser cache cachehit (0 - 1 number)

import { cachehit } from 'page-timing';

const rate = await cachehit(); // 0.855

Pass in a filter function to get results for a subset of resources:

// Javascript files only
const javascriptCacheHitRate = await cachehit({
    filter: ({ name }) => /.m?js[$\?]/.test(name),
    limit: 50
});

// Specific domain
const myCDNCacheHitRate = await cachehit({
    filter: ({ name }) => /https:\/\/[\w-]*.mycdn.com/.test(),
    limit: 50
});

Arguments

  • filter: A filter function to create a subset of files we want to get cache rate for. This function accepts one argument: a PerformanceResourceTiming object. The default is no filter (all resources).
  • limit: A number, in milliseconds, which represents resource load duration that we consider served from cache. The default is 50.

† There are two types of browser cache: memory cache and disk cache. Memory cache will have a duration of 0 (limit: 0) and disk cache will have a higher duration, while still relatively low. For this reason, the default limit value is 50 (milliseconds). This gives a close estimation of browser cache hit-rate.

@omrilotan omrilotan requested a review from a team as a code owner March 1, 2021 11:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant