greatfire / redirect-when-blocked Goto Github PK
View Code? Open in Web Editor NEWRedirect your users to another URL if they can't reach your website
License: MIT License
Redirect your users to another URL if they can't reach your website
License: MIT License
Don't know how to implement this, can you guys provide a more specific guide, thanks!
Hi team,
I am greatly inspired by this project. Just wanted to know if this script is still functional?
Does ServiceWorker buy us anything over AppCache?
Just came across http://jakearchibald.com/2014/offline-cookbook/ which says:
When AppCache arrived on the scene it gave us a couple of patterns to make content work offline. If those were the patterns you needed, congratulations, you won the AppCache lottery (the jackpot remains unclaimed), but the rest of us were left huddled in a corner rocking back & forth.
With ServiceWorker (intro) we gave up trying to solve offline, and gave developers the moving parts to go solve it themselves. It gives you control over caching and how requests are handled. That means you get to create your own patterns. Let's take a look at a few possible patterns in isolation, but in practice you'll likely use many of them in tandem depending on URL & context.
All code examples work today in Chrome 40 beta with the cache polyfill, unless otherwise noted. This stuff will land into the stable version January/February 2015 barring any emergencies, so it won't be long until millions of real users can benefit from this stuff.
For a working demo of some of these patterns, see Trained-to-thrill, and this video showing the performance impact.
(cookbook contents follow)
If so, I guess we can keep an eye on https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorker_API#Browser_support for support in other browsers.
Since we are not caching the website itself, we have to rely on the application cache "fallback" event. If the user has no Internet connection at all, this even is triggered immediately. In the case of DNS poisoning pointing the hostname at a non-responsive IP address, browsers apparently wait for a connection timeout before triggering the fallback event. The connection timeout seems to vary depending on the browser, OS and perhaps other variables such as the network connection itself. Sometimes it seems to be very fast, sometimes it takes more than a minute.
We need to research how browsers handle this and look for a solution.
The .appcache file is served with a "Cache-Control: max-age=0" header so that browsers will always check whether there's a newer version. The .appcache file contains an md5 hash in a comment which is generated based on the file contents in the RWB directory. The effect should be that whenever RWB code or data changes, browsers update their app cache. However, there's a problem. The cached page is itself cached by the CDN. This means that in some instances the browser will reload the application cache but will replace it with a cached version (at the CDN level) of the older page. When the CDN version is replaced, the application cache no longer will refresh it.
Thinking about solutions..
If the site can't be reached, but that's because everything is unavailable (for instance because the client isn't connected to the internet), then you don't need to redirect.
You can check for navigator.onLine
to see what the browser thinks, and maybe try loading a couple scripts to non-controversial domains to see if they load. One example might be
http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js
It should be possible to configure multiple redirection URLs. The site should redirect to the first among these that works.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.