Security News
UK Officials Consider Banning Ransomware Payments from Public Entities
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
perfume.js
Advanced tools
JavaScript library that measures Navigation Timing, First (Contentful) Paint (FP/FCP), First Input Delay (FID) and components lifecycle performance. Report real user measurements to your favorite analytics tool.
Perfume is a tiny, web performance monitoring library which reports field data like Navigation Timing, Resource Timing, First Contentful Paint (FP/FCP), Largest Contentful Paint (LCP), First Input Delay (FID) back to your favorite analytics tool.
English | 简体中文
Perfume leverage the latest W3C Performance Drafts (e.g. PerformanceObserver), for measuring performance that matters! Also known as field data, they allow to understand what real-world users are actually experiencing.
npm (https://www.npmjs.com/package/perfume.js):
npm install perfume.js --save
You can import the generated bundle to use the whole library generated:
import Perfume from 'perfume.js';
Universal Module Definition:
import Perfume from 'node_modules/perfume.js/dist/perfume.umd.min.js';
Metrics like Navigation Timing, Network Information, FP, FCP, FID, and LCP are default reported with Perfume; All results will be reported to the analyticsTracker callback, and the code below is just one way on how you can organize your tracking, feel free to tweak it as you prefer.
const perfume = new Perfume({
analyticsTracker: (options) => {
const { metricName, data, navigatorInformation } = options;
switch (metricName) {
case 'navigationTiming':
if (data && data.timeToFirstByte) {
myAnalyticsTool.track('navigationTiming', data);
}
break;
case 'networkInformation':
if (data && data.effectiveType) {
myAnalyticsTool.track('networkInformation', data);
}
break;
case 'firstPaint':
myAnalyticsTool.track('firstPaint', { duration: data });
break;
case 'firstContentfulPaint':
myAnalyticsTool.track('firstContentfulPaint', { duration: data });
break;
case 'firstInputDelay':
myAnalyticsTool.track('firstInputDelay', { duration: data });
break;
case 'largestContentfulPaint':
myAnalyticsTool.track('largestContentfulPaint', { duration: data });
break;
default:
break;
}
},
logging: false
});
Coo coo coo cool, let's learn something new.
Navigation Timing collects performance metrics for the life and timings of a network request. Perfume helps expose some of the key metrics you might need.
Navigation Timing is run by default.
const perfume = new Perfume({
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
// Perfume.js: NavigationTiming {{'{'}} ... timeToFirstByte: 192.65 {{'}'}}
Resource Timing collects performance metrics for document-dependent resources. Stuff like style sheets, scripts, images, et cetera. Perfume helps expose all PerformanceResourceTiming entries and group data data consumption by Kb used.
const perfume = new Perfume({
resourceTiming: true,
dataConsumption: true,
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
// Perfume.js: dataConsumption { "css": 185.95, "fetch": 0, "img": 377.93, ... , "script": 8344.95 }
FP is the exact time the browser renders anything as visually different from what was on the screen before navigation, e.g. a background change after a long blank white screen time.
First Paint is run by default.
const perfume = new Perfume({
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
// Perfume.js: First Paint 1482.00 ms
FCP is the exact time the browser renders the first bit of content from the DOM, which can be anything from an important image, text, or even the small SVG at the bottom of the page.
First Contentful Paint is run by default.
const perfume = new Perfume({
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
// Perfume.js: First Contentful Paint 2029.00 ms
Largest Contentful Paint (LCP) is an important, user-centric metric for measuring perceived load speed because it marks the point in the page load timeline when the page's main content has likely loaded—a fast LCP helps reassure the user that the page is useful.
const perfume = new Perfume({
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
// Perfume.js: Largest Contentful Paint 2429.00 ms
FID measures the time from when a user first interacts with your site (i.e. when they click a link, tap on a button) to the time when the browser is actually able to respond to that interaction.
First Input Delay is run by default.
const perfume = new Perfume({
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
// Perfume.js: First Input Delay 3.20 ms
CLS is an important, user-centric metric for measuring visual stability because it helps quantify how often users experience unexpected layout shifts—a low CLS helps ensure that the page is delightful.
const perfume = new Perfume({
cumulativeLayoutShift: true,
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
// Perfume.js: Cumulative Layout Shift 3.20 ms
Performance.mark (User Timing API) is used to create an application-defined peformance entry in the browser's performance entry buffer.
const perfume = new Perfume({
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
perfume.start('fibonacci');
fibonacci(400);
perfume.end('fibonacci');
// Perfume.js: fibonacci 0.14 ms
This metric mark the point, immediately after creating a new component, when the browser renders pixels to the screen.
const perfume = new Perfume({
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
})
});
perfume.start('togglePopover');
$(element).popover('toggle');
perfume.endPaint('togglePopover');
// Perfume.js: togglePopover 10.54 ms
Save the data and print it out exactly the way you want it.
const perfume = new Perfume({
analyticsTracker: ({ metricName, data }) => {
myAnalyticsTool.track(metricName, data);
}),
logPrefix: '🍹 HayesValley.js:'
});
perfume.start('fibonacci');
fibonacci(400);
perfume.end('fibonacci');
// 🍹 HayesValley.js: Custom logging 0.14 ms
Configurable analytics callback to use Perfume.js with any platform.
const perfume = new Perfume({
analyticsTracker: (options) => {
const {
data,
metricName,
navigatorInformation,
} = options;
myAnalyticsTool.track(data, metricName, navigatorInformation);
})
});
Default options provided to Perfume.js constructor.
const options = {
// Metrics
cumulativeLayoutShift: false,
dataConsumption: false,
resourceTiming: false,
// Analytics
analyticsTracker: options => {},
// Logging
logPrefix: "Perfume.js:"
logging: true,
maxMeasureTime: 15000,
};
npm run test
: Run test suitenpm run build
: Generate bundles and typingsnpm run lint
: Lints code
Made with ☕️ by @zizzamia and I want to thank some friends and projects for the work they did:
This project exists thanks to all the people who contribute.
Thank you to all our backers! 🙏 [Become a backer]
Code and documentation copyright 2020 Leonardo Zizzamia. Code released under the MIT license. Docs released under Creative Commons.
Leonardo Zizzamia |
5.0.0-rc.1 (2020-4-14)
PerformanceObserver
for all browseranalyticsTracker
by having all duration value inside the data
propertyUntil now, we allowed only Chrome to run the PerformanceObserver interface because of possible cross-browser issues. One in particular related to Firefox 58: https://bugzilla.mozilla.org/show_bug.cgi?id=1403027 Starting from Perfume.js v5.0.0-rc.1, we are going to remove this limitation, and we are going to monitor any new open issues and address them immediately.
Having both duration
and data
inside the analyticsTracker
, it started causing some confusion. Starting from v5, we will keep only data
and have any information from duration
contained inside data
. Please make sure to change the code inside your analyticsTracker
.
FAQs
Web performance library for measuring all User-centric performance metrics, including the latest Web Vitals.
The npm package perfume.js receives a total of 11,396 weekly downloads. As such, perfume.js popularity was classified as popular.
We found that perfume.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.