8o 中文文档教程

发布于 8年前 浏览 27 项目主页 更新于 3年前

8O (Oxide)

8O (Oxide) 是一个 javascript 库,用于获取连接信息,并允许浏览器仅在满足最低速度要求时加载某些内容。

Getting started

Install

安装:npm install --save-dev 8o

之后您可以:

  • Include/copy one of the files in release to your project to start using the full library.
  • Include one or more of the files in src if you require only some of the functionality. The most suitable files for standalone use are:
  • benchmarker.js if you only want to use the speedtest components and not store the results across page navigations.
  • ipmonitor.js if you want to check ip address/connection changes while the user stays on the same webpage.

在所有其他情况下,您可能希望包含 release 文件夹中的整个构建库。

Usage

以下示例确定 3 个文件下载的平均速度,当所有三个文件下载完成后,决定是否显示视频。

var files = [
    'https://upload.wikimedia.org/wikipedia/commons/1/18/F-35_EOTS.jpeg',
    'https://upload.wikimedia.org/wikipedia/commons/6/67/Hydra_70_M261.jpeg',
    'https://upload.wikimedia.org/wikipedia/commons/0/0c/Oasis_Hong_Kong.jpeg'
];

document.addEventListener("onOxideSpeedChange", function(e) {
    console.log( 'Connection speed: ' + Math.round(e.detail.speed) + ' kB/s, last file speed: '+Math.round(e.detail.lastFileSpeed) + ' kB/s, last file size: '+Math.round((e.detail.lastFileLoadTime*e.detail.lastFileSpeed)/1000) + ' kB');
    if( e.detail.queueSize == 0 ) {
        if( e.detail.speed >= 1000 ) {
            document.write('<iframe width="560" height="315" src="https://www.youtube.com/embed/4SNGyKZ1DjM" frameborder="0" allowfullscreen></iframe>');
        }
        else {
            alert('We only recommend video if your internet speed is over 1000 kB/s');
        }
    }
});

var oxide = new Oxide();
for(var i = 0; i < files.length; i++ ) {
    oxide.load(files[i]);
}

Build

如果您从 Github 或 NPM 获取该库,则它是预构建的。 但是,如果您想自定义它或自己构建它,npm 的 package.json 配置文件包含构建命令。

使用 npm run build 从您的源构建版本或使用 npm run 查看所有其他命令的概述。

License

ISC 许可

版权所有 (c) 2017,irbiz.nl 和其他贡献者

允许为任何目的使用、复制、修改或分发此软件 特此授予收费或免费的目的,前提是上述 版权声明和此许可声明出现在所有副本中。

软件按“原样”提供,作者不提供任何保证 关于本软件,包括对适销性的所有默示保证 和健身。 在任何情况下,作者均不对任何特殊的、直接的、 间接或后果性损害或任何由其引起的损害 使用、数据或利润的损失,无论是合同行为、疏忽 或其他侵权行为,因使用或使用而引起或与之相关 本软件的性能。

8O (Oxide)

8O (Oxide) is a javascript library to get connection information and allows the browser to load certain content only if a minimum speed requirements are met.

Getting started

Install

Install: npm install --save-dev 8o

After that you can either:

  • Include/copy one of the files in release to your project to start using the full library.
  • Include one or more of the files in src if you require only some of the functionality. The most suitable files for standalone use are:
  • benchmarker.js if you only want to use the speedtest components and not store the results across page navigations.
  • ipmonitor.js if you want to check ip address/connection changes while the user stays on the same webpage.

In all other scenarios you probably want to include the entire built library from the release folder.

Usage

The following example determines the average speed over 3 file downloads and when all three are done downloading decides wether or not to show a video.

var files = [
    'https://upload.wikimedia.org/wikipedia/commons/1/18/F-35_EOTS.jpeg',
    'https://upload.wikimedia.org/wikipedia/commons/6/67/Hydra_70_M261.jpeg',
    'https://upload.wikimedia.org/wikipedia/commons/0/0c/Oasis_Hong_Kong.jpeg'
];

document.addEventListener("onOxideSpeedChange", function(e) {
    console.log( 'Connection speed: ' + Math.round(e.detail.speed) + ' kB/s, last file speed: '+Math.round(e.detail.lastFileSpeed) + ' kB/s, last file size: '+Math.round((e.detail.lastFileLoadTime*e.detail.lastFileSpeed)/1000) + ' kB');
    if( e.detail.queueSize == 0 ) {
        if( e.detail.speed >= 1000 ) {
            document.write('<iframe width="560" height="315" src="https://www.youtube.com/embed/4SNGyKZ1DjM" frameborder="0" allowfullscreen></iframe>');
        }
        else {
            alert('We only recommend video if your internet speed is over 1000 kB/s');
        }
    }
});

var oxide = new Oxide();
for(var i = 0; i < files.length; i++ ) {
    oxide.load(files[i]);
}

Build

The library comes pre-built if you get it from Github or NPM. However if you want to customise it or build it yourself the package.json config file for npm includes build commands.

Use npm run build to build the releases from your source or npm run to see an overview of all other commands.

License

ISC License

Copyright (c) 2017, irbiz.nl and other contributors

Permission to use, copy, modify, or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文