English | 简体中文
Speed up your website using WebRTC and ServiceWorker.
SW P2P Engine creates a communal, distributed CDN with the latest HTML5 APIs — WebRTC to connect browsers, ServiceWorker to fulfill requests, IndexedDB to cache data, and WebCrypto to do it all securely. And it never impacts the user experience. Ever. This lightweight library uses only a small portion of spare bandwidth, imperceptible CPU, 150MB of browser cache.
Features
- WebRTC data channels for lightweight peer-to-peer communication with no plugins
- Support most popular static assets such as js, css, image and audio.
- Seamlessly fallback to normal server usage if a browser doesn't support WebRTC
- Compatible with all CDNs. No service side changes required.
- Efficient scheduling policies to enhance the performance of P2P streaming
- Use IP database to group up peers by ISP and regions
Browser Support
WebRTC has already been incorporated into the HTML5 standard and it is broadly deployed in modern browsers. The compatibility of SwarmCloud depends on the browser support of WebRTC, Service Worker and IndexedDB.
Compatibility | Chrome | Firefox | Mac Safari | Android Wechat/QQ | Opera | Edge | iOS Safari | IE |
---|---|---|---|---|---|---|---|---|
WebRTC | ||||||||
Service Worker | ||||||||
IndexedDB | ||||||||
SwarmCloud |
Prepare
Register your Domain
Register your domain at https://oms.cdnbye.com
Secure your Site with HTTPS
Secure your site with HTTPS, if it isn't already. HTTPS is required for Service Worker, which we'll set up in the next step.
To secure your site with HTTPS, you can use Let's Encrypt for a free certificate and easy integration. See Let's Encrypt's starting instructions here to secure your site.
Host Service Worker
SwarmCloud's Service Worker is the magic sauce that powers P2P engine.
Host SwarmCloud's Service Worker sw.js at the root of your domain, i.e., https://yourwebsite.com/sw.js. After an asset is cached, every device watches for future requests for that asset and automatically retrieves it from SwarmCloud's peer-to-peer network instead of the more expensive, slower origin server (over WebRTC instead of HTTP).
You can customize configuration or use default one.
Basic Usage
Copy sw.js to your server and make it available at https://yourwebsite.com/sw.js.
Advanced Usage
See here
Install P2P Engine
Add P2P Engine script to the <head>
element of home page. Again, you can customize configuration or use default one.
Basic Usage
Add one line of script to your website homepage index.html, this will setup p2p engine automatically with default configuration.
<head>
<script src="https://cdn.jsdelivr.net/npm/swarmcloud-sw@latest?auto=true"></script>
...
</head>
Note that the script parameter must be "auto = true".
Advanced Usage
See here
Check if SwarmCloud works correctly
Open Chrome Console, if it prints like "ServiceWorker registration successful with scope", that means SwarmCloud is already working.
API and Configuration
See API.md
Open Source Sponsorship
All non-profit sites such as open source projects and blogs can apply for permanent free use, please contact customer service to activate.
Related Projects
- hlsjs-p2p-engine - Web Video Delivery Technology with No Plugins for hls.js.
- dashjs-p2p-engine - Web Video Delivery Technology with No Plugins for MPEG-dash.
- mp4-p2p-engine - Web Video Delivery Technology with No Plugins for MP4.
FAQ
We have collected some frequently asked questions. Before reporting an issue, please search if the FAQ has the answer to your problem.
Contact Us
Email: service@cdnbye.com
Telegram: @cdnbye
Skype: live:86755838