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

html2bigview

v0.1.2

Published

Downloads

11

Readme

html2bigview

原理

一个html页面如何快速变成bigpipe(熟悉bigview)吐出

layout(默认body,可以指定.bp-layout)

div.bp
div.bp

html2bigview

实现步骤

  1. 熟悉bigview demo

https://github.com/i5ting/bigview-koa-demo

2)区分页面

  • body
  • layout()
  • bpmain
  • biglet div#bp-layout #bp-main div.biglet #biglet_1(biglet) // 需要给所有的biglet添加class biglet 并且添加id #biglet_${i} div.biglet #biglet_name(biglet)
  • http爬虫
  • jsdom
  1. 获取元数据

记录所有模块

  • bp-layout
  • bp-main
  • biglet_1
  • biglet_name

4)写生成器

按照bigview-koa-demo

  • index.js
    • add && require
  • biglets

5)发布到npm

  1. 使用方式 以koa项目示例
const html2bigview = require('html2bigview')
// 启用redis来缓存爬虫结果 可选
const redis = require('redis')
const client = redis.createClient()

async index (ctx) {
  await html2bigview(url, {
      zip: true, // 默认是true,压缩html
      redisClient: client, // 默认是false, 使用redis储存爬虫内容,不传使用lru-cache来缓存爬虫内容,lru-cache缓存在重启应用后会失效非永久缓存
      headJs: [], // 需要在head头部或者layout加载的js url,不传入默认全部放在body底部加载
      tplPath: 'src/tpl', 生成的pagelet文件存放的路径,默认是当前工作区的/src/tpl目录下
  })
}

注意事项

一键化转换为bigview渲染模式是一把利剑但不适用于任何场景

优势

  • 服务端能够并行计算并且分块吐出页面
  • 提升看到layout的速度

劣势

  • 相比于直接打开一个html网页多了服务端计算的过程,新增了TTFB时间

适用场景

因该模块是一键化的工作流,所以获取数据的逻辑还是在客户端进行。适用于页面静态内容较多 或者需要分屏展示的页面

如果要进一步提升性能,可以直接手动使用bigview模块,并编写服务端获取数据逻辑

效果展示

demo地址 原html网页地址

测试环境:

MacBook Chrome 性能设置为 fast3G 4xslowdown

统计方式

使用html5的performance api分别在页面头部和body底部打点统计

未使用bigpipe模式

未使用bigpipe ###使用bigpipe模式 使用bigpipe

总结

可以看到pageStart->layout这部分的时间是缩短了很多的,pageStart的时间为输入url到页面执行到该处的时间,视具体设备环境配置网速和服务器配置决定。