(This might not work)
Unpoly wants to emulate a browser that is friendly to apps, not documents
Browsers don't work well when internet goes away
It's not cool to burn down application state when connection is lost.
Can we do better?
a.up-offline
This class will be toggled automatically on all links as network connection is lost or regained.
Links with this class cannot currently be acccessed due to a loss of network connectivity.
Previously cached pages will remain accessible while
the user is offline.
Links to cached pages will not
be assigned the .up-offline
class.
Cache entries don't expire while offline.
a.up-offline {
text-decoration: line-through
}
up.on('up:connection:lost', function(event) {
$('<div class="toast"></div>')
.text("Connection lost")
.appendTo(document.body)
})
up.on('up:connection:restored', function(event) {
$('<div class="toast"></div>')
.text("Connection restored")
.appendTo(document.body)
})
It's not cool to lose form data when connection is lost.
Can we do better?
<form method='post' action='/documents' up-rescue>
<input type="text" name="title">
<input type="file" name="document">
<button type="submit">Submit</button>
</form>
up.on('up:request:rescued', function(event) {
$('<div class="toast"></div>')
.text("Retry: " + event.request.title)
.on('click', event.request.retry)
.appendTo(document.body)
})
What if the page isn't even open when connection is lost?
By moving the Unpoly cache into a service worker we can make cached pages accessible for new tabs.
Even when the user is offline and hasn't yet opened her browser.
But let's try!