Skip to content

Commit 9637f83

Browse files
committed
Updated steps accordingly
1 parent 78f92f6 commit 9637f83

File tree

13 files changed

+123
-94
lines changed

13 files changed

+123
-94
lines changed

src/App.css

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,19 @@
198198
text-align: center;
199199
}
200200

201-
.hightlight {
201+
.highlight {
202202
display: inline-block;
203203
padding-left: 5px;
204204
padding-right: 5px;
205205
background: #f5f5f5;
206+
font-size: inherit;
206207
}
207208

208-
.hightlight.bold {
209+
.highlight.bold {
209210
font-weight: 500;
210211
}
211212

212-
.hightlight.no--bg {
213+
.highlight.no--bg {
213214
background: transparent;
214215
padding: 0;
215216
}
@@ -231,7 +232,8 @@
231232
max-width: 100%;
232233
}
233234

234-
.offline i {
235+
.offline i,
236+
.appshell i {
235237
margin-bottom: 20px;
236238
display: block;
237239
}

src/Menu.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,32 +77,32 @@ class Menu extends Component {
7777
</NavLink>
7878
</li>
7979
<li>
80-
<NavLink to="/serviceworker">
80+
<NavLink to="/appshell">
8181
<span className="menu__steps">3</span>
82-
Service Worker
82+
App Shell
8383
</NavLink>
8484
</li>
8585
<li>
86-
<NavLink to="/offline">
86+
<NavLink to="/serviceworker">
8787
<span className="menu__steps">4</span>
88-
App Shell
88+
Service Worker
8989
</NavLink>
9090
</li>
9191
<li>
92-
<NavLink to="/push">
93-
<span className="menu__steps">5</span>
94-
Push Notification
92+
<NavLink to="/offline">
93+
<span className="menu__steps">6</span>
94+
Offline
9595
</NavLink>
9696
</li>
9797
<li>
98-
<NavLink to="/bgsync">
99-
<span className="menu__steps">6</span>
100-
Background Sync
98+
<NavLink to="/appLike">
99+
<span className="menu__steps">7</span>
100+
App Like
101101
</NavLink>
102102
</li>
103103
<li>
104104
<NavLink to="/finish">
105-
<span className="menu__steps">7</span>
105+
<span className="menu__steps">8</span>
106106
Finish
107107
</NavLink>
108108
</li>

src/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { Router, Route, hashHistory, IndexRoute, IndexRedirect } from 'react-rou
44
import App from './App';
55
import Introduction from './step-1/Introduction';
66
import Setup from './step-2/Setup';
7-
import ServiceWorker from './step-3/ServiceWorker';
8-
import AppShell from './step-4/AppShell';
9-
import Push from './step-5/Push';
10-
import BGSync from './step-6/BGSync';
7+
import AppShell from './step-3/AppShell';
8+
import ServiceWorker from './step-4/ServiceWorker';
9+
import Offline from './step-5/Offline';
10+
import AppLike from './step-6/AppLike';
1111
import Finish from './step-7/Finish';
1212
import PageNotFound from './PageNotFound';
1313
import './index.css';
@@ -21,10 +21,10 @@ ReactDOM.render(
2121
<IndexRedirect to="/introduction" />
2222
<Route path="/introduction" component={Introduction} />
2323
<Route path="/setup" component={Setup} />
24+
<Route path="/appshell" component={AppShell} />
2425
<Route path="/serviceworker" component={ServiceWorker} />
25-
<Route path="/offline" component={AppShell} />
26-
<Route path="/push" component={Push} />
27-
<Route path="/bgsync" component={BGSync} />
26+
<Route path="/offline" component={Offline} />
27+
<Route path="/applike" component={AppLike} />
2828
<Route path="/finish" component={Finish} />
2929
<Route path="*" component={PageNotFound} />
3030
</Route>

src/step-3/AppShell.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React, {Component} from 'react';
2+
import Note from '../Note';
3+
import appShellImg from './app-shell.png';
4+
5+
class AppShell extends Component {
6+
render() {
7+
return(
8+
<div className="appshell">
9+
<h1>What is App Shell Architecture?</h1>
10+
<p>An app shell architecture is minimal level <span className="highlight bold no--bg">HTML, CSS, Javascript</span> required to show the application user interface.</p>
11+
12+
<i>Note: To save some coding time, App shell is already added to the codelabs sample repository.</i>
13+
14+
<div className="offline__container">
15+
<img src={appShellImg} alt="app shell" />
16+
</div>
17+
18+
<Note type="facts">
19+
<p><span>Facts: </span> Housing.com used app shell architecture in their <a href="housing.com" target="_blank">progressive web app</a> to load the page 30% faster than before. Read thier full <a href="https://developers.google.com/web/showcase/2016/pdfs/housing.pdf" target="_blank">case study</a>.</p>
20+
</Note>
21+
</div>
22+
);
23+
}
24+
}
25+
26+
export default AppShell;
File renamed without changes.

src/step-4/AppShell.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/step-3/ServiceWorker.js renamed to src/step-4/ServiceWorker.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ self.addEventListener('fetch', function (event) {
7474
return(
7575
<div className="serviceworker">
7676
<h1>3. Service Worker</h1>
77-
<p>A service worker is a event driven worker which runs in the background and sits in between your application and the browser. It can intercept and handle the network requests for the registered domain. It doesn't have <span className="hightlight bold no--bg">DOM</span> access.</p>
77+
<p>A service worker is a event driven worker which runs in the background and sits in between your application and the browser. It can intercept and handle the network requests for the registered domain. It doesn't have <span className="highlight bold no--bg">DOM</span> access.</p>
7878
<Note type="notes">
79-
<p><span>Tips: </span> Service worker will work only when the page is served via https. For testing and development purposes it works in <span className="hightlight bold no--bg">http://localhost</span>.</p>
79+
<p><span>Tips: </span> Service worker will work only when the page is served via https. For testing and development purposes it works in <span className="highlight bold no--bg">http://localhost</span>.</p>
8080
</Note>
8181

8282
<p>Know more about <a href="https://github.com/w3c/ServiceWorker/blob/master/explainer.md" target="_blank">service worker</a>.</p>
8383

8484
<h2>How to register a service worker?</h2>
85-
<p>A service worker is registered by passing the service-worker file (should be in root directory) in the <span className="hightlight bold">register</span> method which returns a promise like below.</p>
85+
<p>A service worker is registered by passing the service-worker file (should be in root directory) in the <span className="highlight bold">register</span> method which returns a promise like below.</p>
8686
<Highlight lang='javascript' value={registerEvent} />
8787

8888
<h2>Service Worker Lifecycle</h2>
@@ -93,33 +93,33 @@ self.addEventListener('fetch', function (event) {
9393
</ul>
9494

9595
<h2>Install Event</h2>
96-
<p>After registering the service worker, <span className="hightlight bold">install event</span> is fired. Fetch event wont happen unless the install event is successful. But don’t expect them to take control of the page on the first visit, you need to refresh the page to see the effects of service worker.</p>
96+
<p>After registering the service worker, <span className="highlight bold">install event</span> is fired. Fetch event wont happen unless the install event is successful. But don’t expect them to take control of the page on the first visit, you need to refresh the page to see the effects of service worker.</p>
9797

9898
<Highlight lang='javascript' value={installEvent} />
9999

100100
<h2>Activate Event</h2>
101-
<p>After successful install event, <span className="hightlight bold">activate</span> event is fired on various cases. Below are some of them.</p>
101+
<p>After successful install event, <span className="highlight bold">activate</span> event is fired on various cases. Below are some of them.</p>
102102

103103
<h2>When an activate is triggered?</h2>
104104
<ul>
105105
<li>If there is no current active service worker.</li>
106106
<li>On navigating to a page which is in service worker scope.</li>
107-
<li>During the <span className="hightlight bold">push</span>, <span className="hightlight bold">sync</span> event.</li>
107+
<li>During the <span className="highlight bold">push</span>, <span className="highlight bold">sync</span> event.</li>
108108
</ul>
109109

110110
<Highlight lang='javascript' value={activateEvent} />
111111

112112
<Note type="tips">
113-
<p><span>Tips: </span> By using <span className="hightlight bold no--bg">self.clients.claim()</span> method in activate event, we can tell service worker to set itself as the active on current client and all other active clients.</p>
113+
<p><span>Tips: </span> By using <span className="highlight bold no--bg">self.clients.claim()</span> method in activate event, we can tell service worker to set itself as the active on current client and all other active clients.</p>
114114
</Note>
115115

116116
<h2>Fetch Event</h2>
117-
<p>After activate event, <span className="hightlight bold">fetch</span> events are triggered. Whenever the browser requests a resourse within the service worker scope, fetch event can listen to network requests as shown below.</p>
117+
<p>After activate event, <span className="highlight bold">fetch</span> events are triggered. Whenever the browser requests a resourse within the service worker scope, fetch event can listen to network requests as shown below.</p>
118118

119119
<Highlight lang='javascript' value={fetchEvent} />
120120

121121
<h2>Browser Support</h2>
122-
<p>Service worker is supported in <span className="hightlight bold no--bg">Google Chrome</span>, <span className="hightlight bold no--bg">Mozilla Firefox</span>, <span className="hightlight bold no--bg">Opera</span> and support for <span className="hightlight bold no--bg">Microsoft Edge</span> is <a href="https://developer.microsoft.com/en-us/microsoft-edge/platform/status/serviceworker/?q=service%20worker" target="_blank">in development</a>. For <span className="hightlight bold no--bg">Safari</span>, it is still <a href="https://webkit.org/status/?#specification-service-workers" target="_blank">under consideration</a> (🤖).</p>
122+
<p>Service worker is supported in <span className="highlight bold no--bg">Google Chrome</span>, <span className="highlight bold no--bg">Mozilla Firefox</span>, <span className="highlight bold no--bg">Opera</span> and support for <span className="highlight bold no--bg">Microsoft Edge</span> is <a href="https://developer.microsoft.com/en-us/microsoft-edge/platform/status/serviceworker/?q=service%20worker" target="_blank">in development</a>. For <span className="highlight bold no--bg">Safari</span>, it is still <a href="https://webkit.org/status/?#specification-service-workers" target="_blank">under consideration</a> (🤖).</p>
123123
<img src={swSupport} alt="Browser support"/>
124124
<p>More details about service worker <a href="https://jakearchibald.github.io/isserviceworkerready/" target="_blank">browser support</a>.</p>
125125

src/step-5/Offline.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React, {Component} from 'react';
2+
import Highlight from 'react-syntax-highlight';
3+
import appOffline from './offline-app.png';
4+
import cachedResources from './cached-resources.png';
5+
6+
class Offline extends Component {
7+
render() {
8+
const offlineEvent = `/* app.js */
9+
10+
//After DOM is loaded, do offline stuff
11+
document.addEventListener('DOMContentLoaded', function(event) {
12+
//On page load, if user is offline
13+
if (!navigator.onLine) {
14+
//Do some stuff here
15+
}
16+
17+
//Offline Event
18+
window.addEventListener("offline", function () {
19+
//Do some stuff here
20+
});
21+
22+
//Online Event
23+
window.addEventListener("online", function () {
24+
//Do some stuff here
25+
});
26+
});
27+
`;
28+
return(
29+
<div className="offline">
30+
<h1>Offline Experience</h1>
31+
32+
<p>Service worker allow us to use cache API to cache the resources and thus by providing offline experience. By caching the app shell, application loads faster repeated visits.</p>
33+
34+
<div className="offline__container">
35+
<img className="" src={appOffline} alt="app offline" />
36+
</div>
37+
38+
<i>Note: Resources cached via cache API can be view in application tab in chrome DevTools. Refer the below image.</i>
39+
40+
<div className="offline__container">
41+
<img className="" src={cachedResources} alt="cached resources" />
42+
</div>
43+
44+
<p>More details about <a href="https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage">Cache API</a>.</p>
45+
46+
<h2>Taking advantage of built-in events</h2>
47+
<p>By using <span className="highlight bold no--bg">offline/online events</span>, we can let the user know when he is offline or call an API when he has connectivity again.</p>
48+
49+
<Highlight lang='javascript' value={offlineEvent} />
50+
</div>
51+
);
52+
}
53+
}
54+
55+
export default Offline;
File renamed without changes.
File renamed without changes.
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React, {Component} from 'react';
22

3-
class Push extends Component {
3+
class AppLike extends Component {
44
render() {
55
return(
66
<div>
7-
<h1>Push</h1>
7+
<h1>AppLike</h1>
88
</div>
99
);
1010
}
1111
}
1212

13-
export default Push;
13+
export default AppLike;

src/step-6/BGSync.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/syntax.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,10 @@
1111

1212
.hljs::selection,
1313
.hljs span::selection {
14-
background: #4CAF50;
14+
background: #d4d4d4;
15+
}
16+
17+
.hljs::-moz-selection,
18+
.hljs span::-moz-selection {
19+
background: #d4d4d4;
1520
}

0 commit comments

Comments
 (0)