npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web-performance

v0.0.6

Published

collect performance for mobile web (using timing api)

Downloads

11

Readme

收集web用户的性能数据

使用window.performance收集性能数据,应用于android和ios上的web页面

目前safari只支持 Navigation Timing,所以resource类的entries获取不了, markmeasure通过usertiming来polyfill (为了方便,已经把这个项目的文件copy到本项目的polyfill中,用户需要首先加载里面的usertiming.js)

#安装

npm i web-preformance

#api

getMetricsForTiming()

返回timing的性能数据(单位ms),目前返回的数据有:

    start: navigationStart,
    url: window.location.href,
    total: 总耗时(loadEventEnd - navigationStart),
    dns: dns lookup 耗时
    tcp: connect 耗时
    timeToFirstByte: 接受到第一个字节的耗时(responseStart - navigationStart),
    domContentLoading:  domContentLoadedEventStart - domLoading),
    domProcessing: domComplete - domLoading

getMetricsForResource()

返回resource的性能数据,safari下,此项没有意义

requests: 统计发生时,一共多少个资源请求,
domains: 涉及多少域名,
subDomainsOfTdl: 本域名下的子域名个数,
requestsToHost: host一共发起了多少请求,
tldAndSubdomainRequests: host及其子域名一共发起了多少请求,
resources: resources 数组,每个resources的metrics数据:

      name: res.name,
      domain: res.domain,
      fileType: res.fileType,
      initiatorType: res.initiatorType,
      fileExtension: res.fileExtension,
      loadtime: res.loadtime,
      isRequestToHost: res.isRequestToHost,
      requestStartDelay: res.requestStartDelay,//准备开始request和真正开始之间的耗时
      dns: res.dns,
      tcp: res.tcp,
      ttfb: res.ttfb, // timeToFirstByte
      requestDuration: res.requestDuration (responseStart - requestStart)
      ssl: res.ssl( connectEnd - currR.secureConnectionStart)

getMarkAndMeasure()

返回调用时的markmeasure类型的entries(getEntryByType),safari下需配和polyfill/usertiming一起使用,并且是模拟值

返回的格式

data:{
    marks:[],
    measures:[]
}

ready(fn)

有些性能数据,需要window.onload 后才能获取,提供一个简单的借口.注意是onload后,因为执行回调的时候loadEventEnd还没有值,需要一个setTimeout进行延迟执行.

#例子 // 在页面比较前面的位置引入

import perfObj from 'web-performance'

perfObj.ready(function(){
    console.log(perfObj.getMetricsForTiming())
    console.log(perfObj.getMetricsForResource())
})

setTimeout(()=>{
    window.performance.mark('mark_end_xhr');
    window.performance.measure('mark_xhr','mark_start_xhr','mark_end_xhr');
    console.log(perfObj.getMarkAndMeasure())
},1000)

window.performance.mark('mark_start_xhr');

Navigation timing 详细图解

Navigation timing overview

#鸣谢: 统计数据的部分代码来自项目:

performance-bookmarklet

是一个chrome和firefox的插件,可以安装,实际体验一下.