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 🙏

© 2026 – Pkg Stats / Ryan Hefner

fm-check-version-update

v1.0.0

Published

一个轻量级的Web应用版本检查更新库,通过ETag/Last-Modified自动检测版本更新并提示用户刷新

Downloads

100

Readme

fm-check-version-update

一个轻量级的Web应用版本检查更新库,通过ETag/Last-Modified自动检测版本更新并提示用户刷新页面。

特性

  • 🚀 轻量级,无依赖
  • 🔄 自动检测版本更新(基于ETag/Last-Modified)
  • 💡 智能轮询(仅在页面可见时检查)
  • 🎨 优雅的更新提示UI
  • 📦 支持ES模块(ESM)

安装

npm install fm-check-version-update

或使用 yarn:

yarn add fm-check-version-update

使用方法

基础用法

import { initCheckVersion } from 'fm-check-version-update';

// 初始化版本检查
initCheckVersion('my-project-version', 10000); // 每10秒检查一次

参数说明

  • key (string, 必需): localStorage存储的键名,用于区分不同项目
  • interval (number, 必需): 检查间隔时间(毫秒)

完整示例

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>我的应用</title>
</head>
<body>
    <h1>我的应用</h1>
    
    <script type="module">
        import { initCheckVersion } from 'fm-check-version-update';
        
        // 初始化版本检查
        // 参数1: localStorage键名(建议使用项目名称)
        // 参数2: 检查间隔(毫秒),建议10秒以上
        initCheckVersion('my-app-version', 10000);
    </script>
</body>
</html>

在Vue项目中使用

// main.js
import { createApp } from 'vue';
import App from './App.vue';
import { initCheckVersion } from 'fm-check-version-update';

const app = createApp(App);
app.mount('#app');

// 初始化版本检查
initCheckVersion('vue-app-version', 10000);

在React项目中使用

// index.js 或 App.js
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import { initCheckVersion } from 'fm-check-version-update';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<App />);

// 初始化版本检查
initCheckVersion('react-app-version', 10000);

工作原理

  1. 版本检测: 通过请求根路径(/)获取响应头的ETagLast-Modified
  2. 版本对比: 将获取的值与localStorage中存储的值进行对比
  3. 智能轮询:
    • 仅在页面可见时进行轮询检查
    • 页面隐藏时自动停止轮询,节省资源
  4. 更新提示: 检测到版本变化时,显示优雅的更新提示弹窗

注意事项

  1. 服务器配置: 确保服务器正确返回ETagLast-Modified响应头
  2. 检查间隔: 建议设置10秒以上的检查间隔,避免过于频繁的请求
  3. localStorage键名: 不同项目应使用不同的键名,避免冲突
  4. 浏览器兼容性: 需要支持ES模块(ESM)的现代浏览器

API

initCheckVersion(key, interval)

初始化版本检查功能。

参数:

  • key (string): localStorage存储键名
  • interval (number): 检查间隔(毫秒)

示例:

initCheckVersion('my-project-version', 10000);

更新日志

1.0.0

  • 初始版本发布
  • 支持ETag/Last-Modified版本检测
  • 智能轮询机制
  • 优雅的更新提示UI

许可证

ISC

作者

huanghaiqi