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-resource-monitor

v1.3.0

Published

Web resource loading monitoring, callback, reporting, etc, 前端监控资源加载上报

Downloads

72

Readme

web-resource-monitor

Web resource loading monitoring, callback, reporting, etc.
前端监控资源加载上报

If a long resource loading time triggers a callback, you can call HTTP to report the resource file with a long loading time.
如果资源加载长会触发回调,此时可以调用http上报长加载时长的资源文件

Bugs or features can be raised here:
有问题或者扩展功能可以讨论:

github: https://github.com/zhuyue6/web-resource-monitor.git/issues

Getting Started

Install

 npm i web-resource-monitor

resource type matcher and timeout default

match type | value -----|----- audio | wav mp3 wma midi acc cda ape ra video | mp4 mpeg avi 3gp rm wmv flv bd mkv img | jpg jpeg png gif bmp tiff webp css | css ttf script | js vue ts

type | timeout -----|----- audio | 5000 video | 10000 img | 500 css | 100 script | 100

if you want to custom

  
  // get default config
  const { 
    fileMatcherDefault,
    resourceTimeoutConfigDefault 
  } = getResourceConfigDefault()

 // use a new media attr, will replace default,
 // if you set  fileMatcher: {
 //   media: ['mp4'],
 //   video: ['mp4']
  //  }
  //  load aa.mp4 will get twice


  createResourceListener({
    resourceTimeoutConfig: {
      ...resourceTimeoutConfigDefault,
      media: 1000
    },
    fileMatcher: {
      ...fileMatcherDefault,
      media: ['mp4', 'mp3', 'jpg']
    }
  })
  // reset a script, will replace default
  createResourceListener({
    resourceTimeoutConfig: {
      script: 1000
    },
    fileMatcher: {
      script: ['mp4', 'mp3', 'jpg']
    }
  })

How to use

ResourceListener

import { createResourceListener } from 'web-resource-monitor'
import axios from 'axios'

interface Collection {
  name: string
  fileType: string,
  resourceType: string
  initiatorType?: string
  duration: number
}


const resourceListener = createResourceListener()
resourceListener.start()

// listen all loaded event
resourceListener.on('loaded', (collect: Collection, entry: PerformanceEntry) => {
  // After sending an HTTP request, the database exists and can be analyzed using a BI chart
  // if you need more attrs, use entry
  axios.post('xxxxx', collect)
})

// or only listen loadedTimeout event
resourceListener.on('loadedTimeout', (collect: Collection, entry: PerformanceEntry) => {
  console.log(collect)
  // After sending an HTTP request, the database exists and can be analyzed using a BI chart
  // if you need more attrs, use entry
  axios.post('xxxxx', collect)
})


// destroy listener
resourceListener.destroy()

ErrorListener

  import { createErrorListener } from 'web-resource-monitor'

  interface Collection {
    url: string,
    lineno: number,
    colno: number,
    message: string
    stack: string
    browser: string
  }
  const errorListener =  createErrorListener()
  errorListener.start()
  errorListener.on('error', (collect: Collection, error: ErrorEvent) => {
    // After sending an HTTP request, the database exists and can be analyzed using a BI chart
    // if you need more attrs, use error
    axios.post('xxxxx', collect)
  })
  
  // destroy listener
  errorListener.destroy()

both use

  import { createMonitor } from 'web-resource-monitor'

  interface CreateMonitorParams {
    resourceListenerConfig: ResourceReportConfig
  }
  const createMonitorParams: CreateMonitorParams | undefined
  
  const monitor = createMonitor(createMonitorParams)
  monitor.start()
  
  monitor.resourceListener.on('loadedTimeout', (collect: Collection, entry: PerformanceEntry)=>{
    //Same as above
  })

  monitor.errorListener.on('error', (collect: Collection, error: ErrorEvent)=>{
    //Same as above
  })

  // destroy monitor
  monitor.destroy()

umd

use umd and perload can capture more information

<!DOCTYPE html>
  <html>
    <head>
      <meta charset="utf-8">
      <script src="/index.min.js" rel="perload" async>
        const monitor = window.webResourceMonitor.createMonitor()
        monitor.start()
        monitor.resourceListener.on('loadedTimeout', (a, b)=>{
          console.log(a, b)
        })
        monitor.errorListener.on('error', (a, b)=>{
          console.log(a, b)
        })
      </script>
    </head>
    <body></body>
  </html>

License

MIT

Copyright (c) zhuyue