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

html-update-listener

v1.0.9

Published

前端发版后浏览器缓存问题解决方案

Downloads

18

Readme

Introduction

痛点:

前端部署前,用户已经打开了页面,部署后用户不知道网页重新部署了,跳转页面的时候有时候script src的hash变了导致报错跳不过去,严重影响用户体验。

解决方案:

  • 使用webSocket 跟后端进行实时通讯,前端部署完成,后端通过socket推送消息前端。前端接收到信息后,做些事...
  • 接口轮询
  • EvnentSource

以上方案需要后端配合,成本较高

最终方案:

采用fetch('/')轮询请求html,匹配页面script src 的值去判断,每次打包都会生成唯一的hash值,只要轮询去判断不一样了,那一定是重新部署了.

因此诞生了 html-update-listener

Installation

pnpm add html-update-listener

Usage

// main.ts

import HtmlUpdateListener from 'html-update-listener'

// 参数每隔多长时间检测一次当前html是否发生更新了。默认1000ms。这里传了5000,也就是每隔5000ms检测一次。
const updater = new HtmlUpdateListener(5000)


// 注意:检测到html更新会一直触发此回调,你可以调用 controller.destroy()来销毁此回调。
updater.on('update', (controller) => {
   // 你可以在这里做些事!!!
  console.log('html update....')
 
})

// 这种写法只会在html发生改变后只触发一次。
updater.once('update', () => {
  console.log('html update once....')
  // 你可以在这里做些事!!!
})