用于浏览器本地存储的js插件 - jStorage
简介
jStorage是一个跨浏览器的将key-value类型的数据存储到浏览器本地存储的js插件——jStorage支持所有主流浏览器,PC机(甚至包括是IE6)和移动终端均可用。此外,jStorage的实现不依赖任何其它js库(库无关),它和其他js库(Query, Prototype, MooTools等)有良好的兼容性。但是为了让它能够支持老版本的IE(比如蛋疼的IE6),需要依赖第三方库(Prototype, MooTools)或JSON2。
jStorage支持存储Strings,Numbers,JavaScript对象,Arrays,甚至是原生XML节点。 jStorage还支持设置TTL(Time to Live, 生存时间)类型的值用于自动到期存储的keys。最重要的是(也是attractive的) - 当浏览器页签中某个key值变更时或者订阅/发布事件以通知其他标签/窗口的能力。这使得jStorage能够成为Web应用程序本地PubSub(publish/subscribe)平台。
jStorage非常小,min压缩后只有7kb,zip打包后只有4kb。
索引基本信息下载交互测试浏览器支持用法函数参考使用示例问题联系和版权
基本信息jStorage利用HTML5本地存储和IE低版本的userData behavior实现浏览器本地存储。当前的可用情况:jStorage支持所有主流浏览器 — Internet Explorer 6+, Firefox 2+, Safari 4+, Chrome 4+, Opera 10.50+,如果浏览器不支持数据存储,也不会有任何异常产生—— jStorage仍然可以使用,只是没有实际存储而已。下载地址:github (直接下载)交互测试添加一些值,并刷新页面 - 如果您的浏览器支持本地数据存储,那么值应该在页面刷新后依然存在。测试测试订阅/发布事件测试和第三方库并存的功能性单元测试浏览器支持BrowserStorage supportSurvives browser restartSurvives browser crashStorage sizeChrome 4+++5 MBFirefox 3.6+++5 MBFirefox 3+++5 MBFirefox 2+++5 MBIE8+++10 MBIE7+++128 kBIE6+++128 kBOpera 10.50++-5 MBOpera 10.10-N/AN/AN/ASafari 4+++5 MBIphone Safari+++5 MBSafari 3-N/AN/AN/A用法jStorage的使用需要引入Prototype/MooTools/jQuery +jQuery-JSON /JSON2,无论哪种方式,语法保持不变。JSON2Prototype<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script><script src="jstorage.js"></script><script>// Check if "key" exists in the storagevar value = $.jStorage.get("key");if(!value){// if not - load the data from the server value = load_data_from_server() // and save it$.jStorage.set("key",value);}</script>
问题Why would you want to use jStorage when cookies work already in every browser?
Cookies are not meant to save large quantities of data locally - they are meant to pass around ID values to keep track of users. Internet Explorer allows to use up to 20 cookies per domain with the payload of 4kB per cookie. It isn't very much, especially considering the need to chunk larger data into smaller bits. The fact that the data (max. 80 kB) is sent to the server with *every* call doesn't sound much of a good idea either.联系和版权? 2010 - 2012 Andris Reinman, andris.reinman@gmail.com
jStorage is licensed under MIT-styled license, so basically you can do whatever you want to do with it.
最近开发一个需求,同一个浏览器打开了多个页签,用户在一个页签上点了注销按钮,其他浏览器页签也要被注销。用户闲置30分钟超时也要一样的效果。由于不想从后台向前台发事件,计划借助浏览器本地存储的功能实现。闲逛git无意间发现一个开源小插件,简直是为这需求量身定制,因此翻译这篇API文档。
参考:
下载地址:github (直接下载)交互测试添加一些值,并刷新页面 - 如果您的浏览器支持本地数据存储,那么值应该在页面刷新后依然存在。测试测试订阅/发布事件测试和第三方库并存的功能性单元测试浏览器支持BrowserStorage supportSurvives browser restartSurvives browser crashStorage sizeChrome 4+++5 MBFirefox 3.6+++5 MBFirefox 3+++5 MBFirefox 2+++5 MBIE8+++10 MBIE7+++128 kBIE6+++128 kBOpera 10.50++-5 MBOpera 10.10-N/AN/AN/ASafari 4+++5 MBIphone Safari+++5 MBSafari 3-N/AN/AN/A用法jStorage的使用需要引入Prototype/MooTools/jQuery +jQuery-JSON /JSON2,无论哪种方式,语法保持不变。JSON2Prototype<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script><script src="jstorage.js"></script><script>// Check if "key" exists in the storagevar value = $.jStorage.get("key");if(!value){// if not - load the data from the server value = load_data_from_server() // and save it$.jStorage.set("key",value);}</script>
问题Why would you want to use jStorage when cookies work already in every browser?
Cookies are not meant to save large quantities of data locally - they are meant to pass around ID values to keep track of users. Internet Explorer allows to use up to 20 cookies per domain with the payload of 4kB per cookie. It isn't very much, especially considering the need to chunk larger data into smaller bits. The fact that the data (max. 80 kB) is sent to the server with *every* call doesn't sound much of a good idea either.联系和版权? 2010 - 2012 Andris Reinman, andris.reinman@gmail.com
jStorage is licensed under MIT-styled license, so basically you can do whatever you want to do with it.
最近开发一个需求,同一个浏览器打开了多个页签,用户在一个页签上点了注销按钮,其他浏览器页签也要被注销。用户闲置30分钟超时也要一样的效果。由于不想从后台向前台发事件,计划借助浏览器本地存储的功能实现。闲逛git无意间发现一个开源小插件,简直是为这需求量身定制,因此翻译这篇API文档。
参考:
浏览器支持BrowserStorage supportSurvives browser restartSurvives browser crashStorage sizeChrome 4+++5 MBFirefox 3.6+++5 MBFirefox 3+++5 MBFirefox 2+++5 MBIE8+++10 MBIE7+++128 kBIE6+++128 kBOpera 10.50++-5 MBOpera 10.10-N/AN/AN/ASafari 4+++5 MBIphone Safari+++5 MBSafari 3-N/AN/AN/A用法jStorage的使用需要引入Prototype/MooTools/jQuery +jQuery-JSON /JSON2,无论哪种方式,语法保持不变。JSON2Prototype<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script><script src="jstorage.js"></script><script>// Check if "key" exists in the storagevar value = $.jStorage.get("key");if(!value){// if not - load the data from the server value = load_data_from_server() // and save it$.jStorage.set("key",value);}</script>
问题Why would you want to use jStorage when cookies work already in every browser?
Cookies are not meant to save large quantities of data locally - they are meant to pass around ID values to keep track of users. Internet Explorer allows to use up to 20 cookies per domain with the payload of 4kB per cookie. It isn't very much, especially considering the need to chunk larger data into smaller bits. The fact that the data (max. 80 kB) is sent to the server with *every* call doesn't sound much of a good idea either.联系和版权? 2010 - 2012 Andris Reinman, andris.reinman@gmail.com
jStorage is licensed under MIT-styled license, so basically you can do whatever you want to do with it.
最近开发一个需求,同一个浏览器打开了多个页签,用户在一个页签上点了注销按钮,其他浏览器页签也要被注销。用户闲置30分钟超时也要一样的效果。由于不想从后台向前台发事件,计划借助浏览器本地存储的功能实现。闲逛git无意间发现一个开源小插件,简直是为这需求量身定制,因此翻译这篇API文档。
参考:
Prototype<script src="//ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js"></script><script src="jstorage.js"></script><script>// Check if "key" exists in the storagevar value = $.jStorage.get("key");if(!value){// if not - load the data from the server value = load_data_from_server() // and save it$.jStorage.set("key",value);}</script>
问题Why would you want to use jStorage when cookies work already in every browser?
Cookies are not meant to save large quantities of data locally - they are meant to pass around ID values to keep track of users. Internet Explorer allows to use up to 20 cookies per domain with the payload of 4kB per cookie. It isn't very much, especially considering the need to chunk larger data into smaller bits. The fact that the data (max. 80 kB) is sent to the server with *every* call doesn't sound much of a good idea either.联系和版权? 2010 - 2012 Andris Reinman, andris.reinman@gmail.com
jStorage is licensed under MIT-styled license, so basically you can do whatever you want to do with it.
最近开发一个需求,同一个浏览器打开了多个页签,用户在一个页签上点了注销按钮,其他浏览器页签也要被注销。用户闲置30分钟超时也要一样的效果。由于不想从后台向前台发事件,计划借助浏览器本地存储的功能实现。闲逛git无意间发现一个开源小插件,简直是为这需求量身定制,因此翻译这篇API文档。
参考:
jStorage is licensed under MIT-styled license, so basically you can do whatever you want to do with it.
最近开发一个需求,同一个浏览器打开了多个页签,用户在一个页签上点了注销按钮,其他浏览器页签也要被注销。用户闲置30分钟超时也要一样的效果。由于不想从后台向前台发事件,计划借助浏览器本地存储的功能实现。闲逛git无意间发现一个开源小插件,简直是为这需求量身定制,因此翻译这篇API文档。
参考:
http://www.jstorage.info/