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

WIP: Dev service worker #1417

Closed
wants to merge 4 commits into from

Conversation

qinyuhang
Copy link
Contributor

@qinyuhang qinyuhang commented Mar 5, 2021

Fixes #

Proposed Changes

  • Add PWA offline cache, make installed PWA app can work offline.

TODOs

[] In my test, I found out some apis are not cached in the first run. So when I turn my phone to Airplane mode, I navigate to some route, there is no data at all. Maybe There should be one clear list of resources to cache.

[] Cannot offline view a game. It seems the request to sgf is not cached. I shall dig into it.

How to test, The Basic Concept.

1 Your need Proxy https://online-go.com/sw.js to your local build dist sw.js. This requires hijack to https, because it service work requires https to work. And the service works js file must using the same domain with the main site.
2 You need access to your device's browser console to execute code to register service worker. navigator.serviceWorker.register('./sw.js'). We need this code to register service work js file.
3 Above 2 steps must be done in the same device, In the test case it's my iPhone.

@qinyuhang qinyuhang changed the title [WIP]: Dev service worker WIP: Dev service worker Mar 5, 2021
@qinyuhang
Copy link
Contributor Author

How to test(with a iPhone and Mac):

1. Install Charles SSL-Certifacate

Using Charles.app to Proxying SSL, And INSTALL Certification to iPhone and Mac (IMPORTANT! MUST install in both devices!).

Official Manual to install ssl-certifacates
image

2. Build the sw.js from source code.

3. Configure Charles.app

From tool bar map local (Tools => Map Local) to map https://online-go.com/sw.js to actual sw.js which is build from source code.
image

4. Configure iPhone WebInspect

Via Settings => Safari => Advanced => WebInspect.

5. Connect both iPhone and Mac in the same wifi, for Example 'My_Wifi', then get your Mac's IP, for Example 192.168.1.150

6. Configure iPhone Proxy, via Settings => WLAN => My_Wifi => HTTP Proxy => Manual.

Set Server to Mac's IP, 192.168.1.150, port 8888(Charles default port).

7. Using Mac to inspect Safari on iPhone

Connect iPhone to Mac via cable. Using Safari Mac => Development to inspect iPhone Page
image

8. Load św.js

In Inspect, call navigator.serviceWorker.register('./sw.js').
image

9. Finish!

Congratulations! You have done all steps! Now using iPhone Safari Share menu to install to HomeScreen. Then open screen icon. Next set Airplane Mode on. You can see the PWA app works offline.

@qinyuhang
Copy link
Contributor Author

The final result.

RPReplay_Final1614913156.2.MP4

@qinyuhang
Copy link
Contributor Author

How to test, The Basic Concept.

1 Your need Proxy https://online-go.com/sw.js to your local build dist sw.js. This requires hijack to https, because it service work requires https to work. And the service works js file must using the same domain with the main site.
2 You need access to your device's browser console to execute code to register service worker. navigator.serviceWorker.register('./sw.js'). We need this code to register service work js file.
3 Above 2 steps must be done in the same device, In the test case it's my iPhone.

@qinyuhang
Copy link
Contributor Author

qinyuhang commented Mar 5, 2021

Update It is occasionally.

Update. Although service worker cache JS CSS file. I found out the response of some JS file is not promising, Add it to todo.

image

1.7s to réponse jQuery
4.6s to response vender.js

@anoek anoek marked this pull request as draft March 9, 2021 12:18
@anoek
Copy link
Member

anoek commented Mar 24, 2021

Feel free to re-open this PR if you decide to resume this effort

@anoek anoek closed this Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants