add a fallback if js is disabled or sw is not supported
This commit is contained in:
parent
9fc1d6fb7c
commit
fd634988af
25
README.md
25
README.md
|
@ -23,6 +23,25 @@ Source Files: https://github.com/fanhtml5/test-site
|
||||||
|
|
||||||
## FAQ
|
## FAQ
|
||||||
|
|
||||||
|
Q: What if JavaScript is disabled?
|
||||||
|
|
||||||
|
A: Unfortunately, the page can't be displayed. You can add a fallback in `404.html` such as:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<noscript>
|
||||||
|
<meta http-equiv=Refresh content="0;url=FALLBACK_URL">
|
||||||
|
</noscript>
|
||||||
|
<script src=/x.js></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Q: What if the browser doesn't support Service Worker?
|
||||||
|
|
||||||
|
A: Same as above. The program will read the contents of `<noscript>` and render them.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
Q: Is free CDN safe?
|
Q: Is free CDN safe?
|
||||||
|
|
||||||
A: Yes, the program will verify the data integrity.
|
A: Yes, the program will verify the data integrity.
|
||||||
|
@ -59,12 +78,6 @@ A: Just overwrite `x.js`, the client polls this file every 2 minutes.
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Q: What if the browser doesn't support Service Worker?
|
|
||||||
|
|
||||||
A: Unfortunately, the page can't be displayed. You can add a fallback in `404.html`.
|
|
||||||
|
|
||||||
----
|
|
||||||
|
|
||||||
Q: Will new features be added?
|
Q: Will new features be added?
|
||||||
|
|
||||||
A: This project is just an experiment, there is a new project named [freecdn](https://github.com/EtherDream/freecdn) which is much more powerful. (better docs will be released soon)
|
A: This project is just an experiment, there is a new project named [freecdn](https://github.com/EtherDream/freecdn) which is much more powerful. (better docs will be released soon)
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
function pageEnv() {
|
function pageEnv() {
|
||||||
var container = document.documentElement
|
var container = document.documentElement
|
||||||
|
|
||||||
function showErr(msg) {
|
function fallback(html) {
|
||||||
container.innerHTML = msg
|
var noscript = document.getElementsByTagName('noscript')
|
||||||
|
if (noscript.length > 0) {
|
||||||
|
html = noscript[0].innerHTML
|
||||||
|
}
|
||||||
|
container.innerHTML = html
|
||||||
}
|
}
|
||||||
|
|
||||||
function reload() {
|
function reload() {
|
||||||
|
@ -16,11 +20,11 @@ function pageEnv() {
|
||||||
if (jsUrl) {
|
if (jsUrl) {
|
||||||
var sw = navigator.serviceWorker
|
var sw = navigator.serviceWorker
|
||||||
if (!sw) {
|
if (!sw) {
|
||||||
showErr('Error: Service Worker is not supported')
|
fallback('Service Worker is not supported')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var swPending = sw.register(jsUrl).catch(function(err) {
|
var swPending = sw.register(jsUrl).catch(function(err) {
|
||||||
showErr(err.message)
|
fallback(err.message)
|
||||||
})
|
})
|
||||||
rootPath = getRootPath(jsUrl)
|
rootPath = getRootPath(jsUrl)
|
||||||
} else {
|
} else {
|
||||||
|
@ -119,6 +123,7 @@ function pageEnv() {
|
||||||
function loadNextUrl() {
|
function loadNextUrl() {
|
||||||
var url = URLS.shift()
|
var url = URLS.shift()
|
||||||
if (!url) {
|
if (!url) {
|
||||||
|
fallback('failed to load resources')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (PRIVACY === 2) {
|
if (PRIVACY === 2) {
|
||||||
|
|
Loading…
Reference in a new issue