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

gulp-tinystorage

v1.0.2

Published

0.0.1

Downloads

1

Readme

mahua ##简介 gulp-tinystorage是一个gulp插件,用来帮助开发者进行自动化构建,主要作用是将页面中的js加载按文件的md5进行localstorage存储,旨在减少一次或多次的js资源加载,哪怕服务端做了304相应的,依然能减少一次网络请求,还是有很强的实用价值

##安装

npm install tiny-storage

#使用场景 首先需要你的每一个js文件都是严格按照模块化思想(AMD、CMD)开发,即js文件只做模块定义,坚决不能有自执行的js模块,当然(function() {}) ()子执行是没有问题的。

需要您 的CDN支持combourl模式的加载,即能通过一个url访问加载物理上不同的模块,如: 腾讯的CDN combo加载为http://wx.gtimg.com/c/=a.js,b.js,c.js

页面的启动点是唯一的,类似如下形式。

<script type="text/javascript">
 require ('startup') ();
</script>

##用法 在gulp的构建流中使用即可,开发者在开发时可用fiddler(Mac下可使用Charles)做辅助的请求转发

对于html页面需要如下的格式

<!--tinystorage-->
<script type="text/javascript" src="./js/a.js"></script>
<script type="text/javascript" src="./js/c.js"></script>
<!--endtinystorage-->
<!--tinystorage-->
<script type="text/javascript" src="./js/b.js"></script>
<!--endtinystorage-->

用gulp进行如下的构建

gulp.src ('./index.html')
    .pipe (tinyStorage({
        combourl: function (list) {
            return 'http://www.test.com/c/=' + list.join(',')
        }
    }))
    .pipe (gulp.dest ('./dist'))

其中的comburl传入需要加载的模块文件名,你需要按照你自己的规则拼接成一个combourl。

构建后变为如此形式:

<script type="text/javascript">(function () {var list=[];if (window.localStorage) {
    if (localStorage["tinystorage-a-463c4e8c391639aaa2459d9c72c45329.js"]) {
	var sc = document.createElement("script");
	sc.text=["(",localStorage["tinystorage-a-463c4e8c391639aaa2459d9c72c45329.js"],") ()"].join("")
	document.body.appendChild(sc);
}else {
list.push ("a-463c4e8c391639aaa2459d9c72c45329.js")
}
}else {list.push ("a-463c4e8c391639aaa2459d9c72c45329.js")}
...
...

如此实现如果文件没有版本更新(md5一致)则优先从localstorage获取模块定义,否则加入到变化列表等待加载。

收集到所有发生版本变更的js文件,使用一次combourl进行一次统一加载,加载完成后会更新原有的localstorage存储(删除老的,加入新的)

这样每次发布我们只需要发布有变更的模块,避免因一个小模块的变动导致整体cache失效的问题