You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>An app shell architecture is minimal level <spanclassName="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
+
<divclassName="offline__container">
15
+
<imgsrc={appShellImg}alt="app shell"/>
16
+
</div>
17
+
18
+
<Notetype="facts">
19
+
<p><span>Facts: </span> Housing.com used app shell architecture in their <ahref="housing.com"target="_blank">progressive web app</a> to load the page 30% faster than before. Read thier full <ahref="https://developers.google.com/web/showcase/2016/pdfs/housing.pdf"target="_blank">case study</a>.</p>
Copy file name to clipboardExpand all lines: src/step-4/ServiceWorker.js
+9-9Lines changed: 9 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -74,15 +74,15 @@ self.addEventListener('fetch', function (event) {
74
74
return(
75
75
<divclassName="serviceworker">
76
76
<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 <spanclassName="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 <spanclassName="highlight bold no--bg">DOM</span> access.</p>
78
78
<Notetype="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 <spanclassName="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 <spanclassName="highlight bold no--bg">http://localhost</span>.</p>
80
80
</Note>
81
81
82
82
<p>Know more about <ahref="https://github.com/w3c/ServiceWorker/blob/master/explainer.md"target="_blank">service worker</a>.</p>
83
83
84
84
<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 <spanclassName="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 <spanclassName="highlight bold">register</span> method which returns a promise like below.</p>
@@ -93,33 +93,33 @@ self.addEventListener('fetch', function (event) {
93
93
</ul>
94
94
95
95
<h2>Install Event</h2>
96
-
<p>After registering the service worker, <spanclassName="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, <spanclassName="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>
97
97
98
98
<Highlightlang='javascript'value={installEvent}/>
99
99
100
100
<h2>Activate Event</h2>
101
-
<p>After successful install event, <spanclassName="hightlight bold">activate</span> event is fired on various cases. Below are some of them.</p>
101
+
<p>After successful install event, <spanclassName="highlight bold">activate</span> event is fired on various cases. Below are some of them.</p>
102
102
103
103
<h2>When an activate is triggered?</h2>
104
104
<ul>
105
105
<li>If there is no current active service worker.</li>
106
106
<li>On navigating to a page which is in service worker scope.</li>
107
-
<li>During the <spanclassName="hightlight bold">push</span>, <spanclassName="hightlight bold">sync</span> event.</li>
107
+
<li>During the <spanclassName="highlight bold">push</span>, <spanclassName="highlight bold">sync</span> event.</li>
<p><span>Tips: </span> By using <spanclassName="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 <spanclassName="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>
114
114
</Note>
115
115
116
116
<h2>Fetch Event</h2>
117
-
<p>After activate event, <spanclassName="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, <spanclassName="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>
118
118
119
119
<Highlightlang='javascript'value={fetchEvent}/>
120
120
121
121
<h2>Browser Support</h2>
122
-
<p>Service worker is supported in <spanclassName="hightlight bold no--bg">Google Chrome</span>, <spanclassName="hightlight bold no--bg">Mozilla Firefox</span>, <spanclassName="hightlight bold no--bg">Opera</span> and support for <spanclassName="hightlight bold no--bg">Microsoft Edge</span> is <ahref="https://developer.microsoft.com/en-us/microsoft-edge/platform/status/serviceworker/?q=service%20worker"target="_blank">in development</a>. For <spanclassName="hightlight bold no--bg">Safari</span>, it is still <ahref="https://webkit.org/status/?#specification-service-workers"target="_blank">under consideration</a> (🤖).</p>
122
+
<p>Service worker is supported in <spanclassName="highlight bold no--bg">Google Chrome</span>, <spanclassName="highlight bold no--bg">Mozilla Firefox</span>, <spanclassName="highlight bold no--bg">Opera</span> and support for <spanclassName="highlight bold no--bg">Microsoft Edge</span> is <ahref="https://developer.microsoft.com/en-us/microsoft-edge/platform/status/serviceworker/?q=service%20worker"target="_blank">in development</a>. For <spanclassName="highlight bold no--bg">Safari</span>, it is still <ahref="https://webkit.org/status/?#specification-service-workers"target="_blank">under consideration</a> (🤖).</p>
123
123
<imgsrc={swSupport}alt="Browser support"/>
124
124
<p>More details about service worker <ahref="https://jakearchibald.github.io/isserviceworkerready/"target="_blank">browser support</a>.</p>
<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>
<p>More details about <ahref="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 <spanclassName="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>
0 commit comments