Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network-first service worker caches #2515

Merged
merged 3 commits into from
Jul 25, 2018
Merged

Conversation

xPaw
Copy link
Member

@xPaw xPaw commented Jun 5, 2018

This adds offline "support". The Lounge itself won't connect or show messages, but at least it will render the loading screen and will keep trying to connect to the server.

This is also required for "add to home" in Chrome 68, as they changed the rules.

And finally this allows generating a proper PWA apk on Android, as Chrome considers it a proper PWA app now.

@SinZ163 for review

@xPaw xPaw added the Type: Feature Tickets that describe a desired feature or PRs that add them to the project. label Jun 5, 2018
@xPaw xPaw added this to the 3.0.0 milestone Jun 5, 2018
@xPaw xPaw force-pushed the xpaw/transparent-sw-cache branch 3 times, most recently from e492c21 to 98670e3 Compare June 5, 2018 15:31
@xPaw
Copy link
Member Author

xPaw commented Jun 5, 2018

Install from dropdown App details
screenshot_20180605-183350 screenshot_20180605-183402
Chrome 68 suggestion Chrome 68 button in settings
screenshot_20180605-183733 screenshot_20180605-183739

@xPaw xPaw requested a review from a team June 5, 2018 18:56
@xPaw xPaw force-pushed the xpaw/transparent-sw-cache branch 2 times, most recently from f9dac3c to 439a798 Compare June 13, 2018 14:50
@xPaw xPaw requested a review from astorije June 19, 2018 07:10
@xPaw xPaw force-pushed the xpaw/transparent-sw-cache branch from 439a798 to 89850f3 Compare June 19, 2018 16:26
@xPaw
Copy link
Member Author

xPaw commented Jul 5, 2018

Been running this without problems.

@@ -14,6 +14,11 @@
</div>

<div class="row">
<div class="col-sm-12" id="webAppInstallButton" style="display:none">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class instead of inline style?

Copy link
Member Author

@xPaw xPaw Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to hidden attribute

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or hidden CSS class? 🤷‍♂️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hidden attribute is in standard, so makes sense to use that.

@xPaw xPaw force-pushed the xpaw/transparent-sw-cache branch from 89850f3 to ab1ce4e Compare July 6, 2018 09:42
@xPaw xPaw force-pushed the xpaw/transparent-sw-cache branch from ab1ce4e to 28df906 Compare July 6, 2018 12:39
@astorije
Copy link
Member

I need to play with this a bit but code looks good to me.

I have extremely low confidence that this works as expected on iOS (though who knows, maybe it does), so @McInkay if you want to test it on Android as well that would be great.

@@ -9,6 +9,10 @@ let clientSubscribed = null;
let applicationServerKey;

if ("serviceWorker" in navigator) {
window.addEventListener("beforeinstallprompt", (e) => {
e.prompt();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do?

@@ -44,7 +44,7 @@ audio:not([controls]) {
}
[hidden],
template {
display: none;
display: none !important;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Euch


// Trigger early service worker registration
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("service-worker.js");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already register a service worker, right? Will this conflict with that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it doesn't, the second registration will just resolve instantly.

installPromptEvent.prompt();
}

$(this).prop("hidden", true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user removes it from the homescreen, that means this button won't be visible anymore, correct? Should we not remove it?

Copy link
Member Author

@xPaw xPaw Jul 18, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reloading the page will make it appear again, or depending on how the event gets called?

installPromptEvent can be prompted only once anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, so it'll always re-show on refresh, of course. That feels less than ideal.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it only shows whenever the browser feels like the user can be prompted (that's what Chrome devs suggest doing). It's on the settings page anyway.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant the button on the settings page. Are we not hiding it when it's installed here, or have I misunderstood?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The button only shows up when the browser triggers the event. I believe it won't trigger the event if you already have it on the homescreen (thus no button will show up).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the button is defined as just html...

<button type="button" class="btn" id="webapp-install-button" hidden>Add The Lounge to Home screen</button>

Does chrome find this button and hide it itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hidden attribute

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm an idiot.

const excludedPathsFromCache = /^(?:socket\.io|storage|uploads|cdn-cgi)\//;

self.addEventListener("install", function() {
self.skipWaiting();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@astorije astorije left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, thanks @xPaw and previous reviewers!

@astorije astorije removed their assignment Jul 25, 2018
@astorije astorije merged commit 7b926f7 into master Jul 25, 2018
@astorije astorije deleted the xpaw/transparent-sw-cache branch July 25, 2018 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Tickets that describe a desired feature or PRs that add them to the project.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants