Unlimited bandwidth, low-cost to build a website (c)

Front-end proxy

HTML5 era of black science and technology after another, but perhaps the most innovative to the number of Service Worker, and it can even subvert the traditional B / S network architecture.

As the name suggests, Service is a service program, and the Worker commonly used in multi-threaded. Hence Service Worker (hereinafter referred to as SW) is an independent of the page, the browser sustainable daemon running.

SW provides a set of API, allows developers to intercept the site under their own sites all pages produced all requests , and can customize the response results. (Except for some special requests can not be intercepted)

This, like open a reverse proxy service locally!

With so Guards function, load balancing at the front is very easy, and even achieve results in the past can not imagine - the real-time seamless handover.

Real-time switch

As a proxy, when the SW failed to load upstream resources, may choose not to return incorrect results, but try again to load the backup site until you return to the correct result, only a response to the downstream web page:

Page view, this is just an ordinary request and response - perhaps with a longer time, but the result is still normal. SW retry the details of, for business is completely transparent!

Compared DNS cache time there are at least a few seconds, this embodiment by a program-controlled, switchable source site in a very short period of time. So even if some nodes fail, even pages have no perception!

Check encryption

In addition to change the URL, SW course can manipulate the data returned.

This means that we can add a verification mechanism to detect whether resources have been tampered with. So those issues inline ads, add watermarks and the like, can be a good solution!

In addition, we can also encrypt the original data, and then decrypted by the SW. This privacy is not high node, it makes sense.

For example Raw Git as a free space, all our files can be found on GitHub repository where anyone can easily see. However, if the file is encrypted, while the decryption algorithm in SW obfuscate protection, can increase the difficulty of the view - at least GitHub search capabilities, as well as ordinary spider, it is not caught up in plain text content.

Furthermore, we can even be re-stored Hash file name. In this way, exposed just a bunch of garbage, no directory hierarchy of files!

Offline start

We mentioned earlier, SW intercept the page where the request. SW is turned on after the fact, visit the page itself will be subject to SW.

This means: as long as the user installed SW, after all requests can be proxied to the external node, so consumption can significantly reduce traffic to your site!

So even if our website is down, but as long as there is a node available, the user can still access the normal!

Streamline start

In order to meet the new user in the tight bandwidth, we "mini-starter" in reference to the program before, the resources required to install SW, downsized to a minimum - only two tiny final documents: html and js files . (SW script must under the current site)

When a user first visits, regardless of which URL access, we return to this html file to install the SW service; After the installation is complete, the page automatically refreshes when all requests have gone SW agents!

Content on the html, and as previously discussed, all functionality is provided by an external script to achieve:

<script src=//free-host-n.net/boot.js></script>

The contents SW script, the same can also be placed on the outside:

importScripts('//free-host-n.net/sw.js')

So, our site only carries two very small files, you can get endless bandwidth!

The cost of renovation

Strong cache compared to the previous scheme, now do not need to use SW front end in any way changed, the page where the resource remains of the original path. As with VPN, without requiring any modification to the application, will be able to turn on the flow automatically forwarded to the proxy, using them is very simple.

In this way, a website can easily access any use!

Indeed SW effect can be achieved far more than that, we continue to dig it.

Next

Guess you like

Origin yq.aliyun.com/articles/717848