|
1 | | -# Module 9: Adding Offline Support to Web Applications. |
| 1 | +# Module 9: Adding Offline Support to Web Applications |
2 | 2 |
|
3 | | -# Lab: Adding Offline Support to Web Applications. |
| 3 | +# Lab: Adding Offline Support to Web Applications |
4 | 4 |
|
5 | 5 | ### Lab Setup |
6 | 6 |
|
7 | 7 | ### Preparation Steps |
8 | 8 |
|
9 | | -1. Ensure that you have cloned the 20480C directory from GitHub. It contains the code segments for this course's labs and demos. https://github.com/MicrosoftLearning/20480-Programming-in-HTML5-with-JavaScript-and-CSS3/tree/master/Allfiles. |
| 9 | +Ensure that you have cloned the 20480C directory from GitHub (**https://github.com/MicrosoftLearning/20480-Programming-in-HTML5-with-JavaScript-and-CSS3/tree/master/Allfiles**). It contains the code segments for the labs and demos in this course. |
10 | 10 |
|
11 | | -### Exercise 1: Caching Offline Data by Using the Application Cache API. |
| 11 | +### Exercise 1: Caching Offline Data by Using the Application Cache API |
12 | 12 |
|
13 | | -#### Task 1: Configure the application cache manifest. |
| 13 | +#### Task 1: Configure the application cache manifest |
14 | 14 |
|
15 | | -1. On the Windows 10 **Start** screen, click the **Desktop** tile. |
16 | | -2. On the Windows taskbar, click **Microsoft Edge**. |
17 | | -3. In the Microsoft Edge, press F10 to display the menu bar. |
| 15 | +1. On the **Start** menu, click the **Desktop** tile. |
| 16 | +2. On the taskbar, click Microsoft Edge. |
| 17 | +3. In Microsoft Edge, to display the menu bar, press F10. |
18 | 18 | 4. On the **Tools** menu, click **Internet options**. |
19 | 19 | 5. In the **Internet Options** dialog box, click **Settings**. |
20 | 20 | 6. In the **Website Data Settings** dialog box, click the **Caches and databases** tab. |
21 | 21 | 7. Select the **Allow website caches and databases** check box, and then click **OK**. |
22 | 22 | 8. In the **Internet Options** dialog box, click **OK**. |
23 | 23 | 9. Close Microsoft Edge. |
24 | | -10. Open **Visual Studio 2017**. |
| 24 | +10. Open Microsoft Visual Studio 2017. |
25 | 25 | 11. In Visual Studio, on the **File** menu, point to **Open**, and then click **Project/Solution**. |
26 | | -12. In the **Open Project** dialog box, browse to **Allfiles\Mod09\Labfiles\Starter\Exercise 1**, click **ContosoConf.sln**, and then click **Open**. |
27 | | -13. In Solution Explorer, expand the **ContosoConf** project node, and then double-click **appcache.manifest**. |
| 26 | +12. In the **Open Project** dialog box, browse to **Allfiles\Mod09\Labfiles\Starter\Exercise 1**, and then open the **ContosoConf.sln** solution. |
| 27 | +13. In **Solution Explorer**, expand the **ContosoConf** project node, and then double-click **appcache.manifest**. |
28 | 28 | 14. Find the following comment: |
29 | | - ```javascript |
| 29 | + ```javascript |
30 | 30 | # TODO: Add index, about, schedule and location pages |
31 | | - ``` |
| 31 | + ``` |
32 | 32 | 15. After the comment, type the following URLs: |
33 | | - ```javascript |
| 33 | + ```javascript |
34 | 34 | /index.htm |
35 | 35 | /about.htm |
36 | 36 | /location.htm |
37 | 37 | /schedule.htm |
38 | | - ``` |
39 | | -16. In Solution Explorer, double-click **index.htm**. |
40 | | -17. Add the **manifest** attribute to the **<html>** element, as shown in bold below: |
41 | | - ```html |
| 38 | + ``` |
| 39 | +16. In **Solution Explorer**, double-click **index.htm**. |
| 40 | +17. Add the **manifest** attribute to the **<html>** element, as shown below: |
| 41 | + ```html |
42 | 42 | <html lang="en" manifest="/appcache.manifest"> |
43 | | - ``` |
44 | | -18. In Solution Explorer, double-click **about.htm**. |
45 | | -19. Add the manifest attribute to the **<html>** element, as shown in bold below: |
46 | | - ```html |
| 43 | + ``` |
| 44 | +18. In **Solution Explorer**, double-click **about.htm**. |
| 45 | +19. Add the manifest attribute to the **<html>** element, as shown below: |
| 46 | + ```html |
47 | 47 | <html lang="en" manifest="/appcache.manifest"> |
48 | | - ``` |
49 | | -20. In Solution Explorer, double-click **schedule.htm**. |
50 | | -21. Add the manifest attribute to the **<html>** element, as shown in bold below: |
51 | | - ```html |
| 48 | + ``` |
| 49 | +20. In **Solution Explorer**, double-click **schedule.htm**. |
| 50 | +21. Add the **manifest** attribute to the **<html>** element, as shown below: |
| 51 | + ```html |
52 | 52 | <html lang="en" manifest="/appcache.manifest"> |
53 | | - ``` |
54 | | -22. In Solution Explorer, double-click **location.htm**. |
55 | | -23. Add the manifest attribute to the **<html>** element, as shown in bold below: |
56 | | - ```html |
| 53 | + ``` |
| 54 | +22. In **Solution Explorer**, double-click **location.htm**. |
| 55 | +23. Add the **manifest** attribute to the **<html>** element, as shown below: |
| 56 | + ```html |
57 | 57 | <html lang="en" manifest="/appcache.manifest"> |
58 | | - ``` |
| 58 | + ``` |
59 | 59 |
|
60 | | -#### Task 2: Detect offline mode by using JavaScript code. |
| 60 | +#### Task 2: Detect offline mode by using a JavaScript code |
61 | 61 |
|
62 | | -1. In Solution Explorer, expand the **scripts** folder, and then double-click **offline.js**. |
| 62 | +1. In **Solution Explorer**, expand the **scripts** folder, and then double-click **offline.js**. |
63 | 63 | 2. Find the following comment: |
64 | | - ```javascript |
| 64 | + ```javascript |
65 | 65 | // TODO: if currently offline, hide navigation links that require online |
66 | | - ``` |
| 66 | + ``` |
67 | 67 | 3. After this comment, add the following JavaScript code: |
68 | | - ```javascript |
| 68 | + ```javascript |
69 | 69 | if (!navigator.onLine) { |
70 | 70 | hideLinksThatRequireOnline(); |
71 | 71 | } |
72 | | - ``` |
| 72 | + ``` |
73 | 73 | 4. Find the following comment: |
74 | | - ```javascript |
| 74 | + ```javascript |
75 | 75 | // TODO: add onoffline and ononline events to document.body |
76 | | - ``` |
| 76 | + ``` |
77 | 77 | 5. After the second line of this comment, add the following JavaScript code: |
78 | | - ```javascript |
| 78 | + ```javascript |
79 | 79 | document.body.onoffline = hideLinksThatRequireOnline; |
80 | 80 | document.body.ononline = showLinks; |
81 | | - ``` |
| 81 | + ``` |
82 | 82 | 6. Find the following comment: |
83 | | - ```javascript |
| 83 | + ```javascript |
84 | 84 | // TODO: also handle the applicationCache error event to hide links |
85 | | - ``` |
| 85 | + ``` |
86 | 86 | 7. After this comment, add the following JavaScript code: |
87 | | - ```javascript |
| 87 | + ```javascript |
88 | 88 | applicationCache.addEventListener("error", hideLinksThatRequireOnline, false); |
89 | | - ``` |
| 89 | + ``` |
90 | 90 |
|
91 | | -#### Task 3: Test the application. |
| 91 | +#### Task 3: Test the application |
92 | 92 |
|
93 | | -1. In Solution Explorer, double-click **index.htm**. |
| 93 | +1. In **Solution Explorer**, double-click **index.htm**. |
94 | 94 | 2. On the **Debug** menu, click **Start Without Debugging**. |
95 | | -3. In Microsoft Edge, if the message **Intranet settings are turned off by default** appears, click **Don’t show this message again**. |
| 95 | +3. In **Microsoft Edge**, if the **Intranet settings are turned off by default** message appears, click **Don’t show this message again**. |
96 | 96 | 4. Verify that Microsoft Edge displays the **Home** page. |
97 | | -5. Expand the Windows notification area, right-click **IIS Express**, and then click **Exit**. |
| 97 | +5. Expand the Windows notification area, right-click **IIS Express**, and then select **Exit**. |
98 | 98 |
|
99 | | ->**Note:** When IIS Express first starts running, the IIS Express icon may appear in the Windows task bar rather than the notification area. If this occurs, right-click the **IIS Express** icon and then click **Exit**. |
| 99 | +>**Note**: When **IIS Express** first starts running, the **IIS Express** icon may appear on the taskbar rather than the notification area. If this occurs, right-click the **IIS Express** icon on the taskbar, and then select **Exit**. |
100 | 100 |
|
101 | 101 |
|
102 | 102 |  |
103 | 103 |
|
104 | 104 | 6. In the **Confirmation** dialog box, click **Yes**. |
105 | 105 | 7. In Microsoft Edge, click **Schedule**. |
106 | 106 | 8. Verify that the page loads and displays the schedule information. |
107 | | -9. Wait five seconds, and then verify that the web site navigation bar no longer displays the **Register** link. |
| 107 | +9. Wait for five seconds, and then verify that the website navigation bar no longer displays the **Register** link. |
108 | 108 | 10. Click **About**. |
109 | 109 | 11. Verify that the page loads and displays the information describing the conference. |
110 | | -12. Verify that the web site navigation bar no longer displays the **Register** link. |
| 110 | +12. Verify that the website navigation bar does not display the **Register** link. |
111 | 111 | 13. Close Microsoft Edge. |
112 | 112 |
|
113 | | ->**Results:** After completing this exercise, you will have modified the web application and made the **Home**, **About**, **Schedule**, and **Location** pages available offline. |
| 113 | +>**Results**: After completing this exercise, you will have modified the web application and made the **Home**, **About**, **Schedule**, and **Location** pages available offline. |
114 | 114 |
|
115 | | -### Exercise 2: Persisting User Data by Using the Local Storage API. |
| 115 | +### Exercise 2: Persisting User Data by Using the Local Storage API |
116 | 116 |
|
117 | | -#### Task 1: Observe the current behavior of the Schedule page. |
| 117 | +#### Task 1: Observe the current behavior of the Schedule page |
118 | 118 |
|
119 | 119 | 1. In Visual Studio, on the **File** menu, click point to **Open**, and then click **Project/Solution**. |
120 | | -2. In the **Open Project** dialog box, browse to **Allfiles\Mod09\Labfiles\Starter\Exercise 2**, click **ContosoConf.sln**, and then click **Open**. |
121 | | -3. In Solution Explorer, expand the **ContosoConf** project, and then double-click **schedule.htm**. |
| 120 | +2. In the **Open Project** dialog box, browse to **Allfiles\Mod09\Labfiles\Starter\Exercise 2**, and then open the **ContosoConf.sln** solution. |
| 121 | +3. In **Solution Explorer**, expand the **ContosoConf** project, and then double-click **schedule.htm**. |
122 | 122 | 4. On the **Debug** menu, click **Start Without Debugging**. |
123 | | -5. Expand the Windows notification area, right-click **IIS Express**, and then click **Exit**. |
| 123 | +5. Expand the Windows notification area, right-click **IIS Express**, and then select **Exit**. |
124 | 124 | 6. In the **Confirmation** dialog box, click **Yes**. |
125 | | -7. In Microsoft Edge, click the star icon in the **Registration** box, and verify that the icon is now colored yellow. |
| 125 | +7. In Microsoft Edge, in the **Registration** box, click the star icon, and then verify that the icon is now colored yellow. |
126 | 126 | 8. Click **Refresh**. |
127 | 127 | 9. Verify that the star icon for **Registration** is now colored white. |
128 | 128 | 10. Close Microsoft Edge. |
129 | 129 |
|
130 | | -#### Task 2: Save information about starred session to local storage. |
| 130 | +#### Task 2: Save information about starred sessions to local storage |
131 | 131 |
|
132 | | -1. In Solution Explorer, expand the **ContosoConf** project, expand the **scripts** folder, and then double-click **LocalStarStorage.js**. |
| 132 | +1. In **Solution Explorer**, expand the **ContosoConf** project, expand the **scripts** folder, and then double-click **LocalStarStorage.js**. |
133 | 133 | 2. Find the following comments: |
134 | | - ```javascript |
| 134 | + ```javascript |
135 | 135 | // TODO: convert this.sessions into a JSON string |
136 | 136 |
|
137 | 137 | // TODO: save this JSON string into local storage as "stars" |
138 | | - ``` |
| 138 | + ``` |
139 | 139 | 3. After the second comment, insert the following JavaScript code: |
140 | | - ```javascript |
| 140 | + ```javascript |
141 | 141 | this.localStorage.setItem("stars", JSON.stringify(this.sessions)); |
142 | | - ``` |
| 142 | + ``` |
143 | 143 |
|
144 | | -#### Task 3: Load information about starred session from local storage. |
| 144 | +#### Task 3: Load information about starred sessions from local storage |
145 | 145 |
|
146 | 146 | 1. In **LocalStarStorage.js**, find the following comment: |
147 | | - ```javascript |
| 147 | + ```javascript |
148 | 148 | // TODO: get the "stars" from local storage |
149 | | - ``` |
| 149 | + ``` |
150 | 150 | 2. After this comment, add the following JavaScript code: |
151 | | - ```javascript |
| 151 | + ```javascript |
152 | 152 | var json = this.localStorage.getItem("stars"); |
153 | | - ``` |
| 153 | + ``` |
154 | 154 | 3. Find the following comments: |
155 | | - ```javascript |
| 155 | + ```javascript |
156 | 156 | // TODO: parse the JSON string into this.sessions |
157 | 157 |
|
158 | 158 | // TODO: handle failures due to missing data etc |
159 | | - ``` |
| 159 | + ``` |
160 | 160 | 4. After the second comment, add the following JavaScript code: |
161 | | - ```javascript |
| 161 | + ```javascript |
162 | 162 | if (json) { |
163 | 163 | try { |
164 | 164 | this.sessions = JSON.parse(json) || []; |
|
168 | 168 | } else { |
169 | 169 | this.sessions = []; |
170 | 170 | } |
171 | | - ``` |
| 171 | + ``` |
172 | 172 |
|
173 | | -#### Task 4: Use the local storage wrapper to save and load data in the Schedule page. |
| 173 | +#### Task 4: Use the local storage wrapper to save and load data in the Schedule page |
174 | 174 |
|
175 | | -1. In Solution Explorer, expand the **scripts** folder, then double-click **ScheduleItem.js**. |
| 175 | +1. In **Solution Explorer**, expand the **scripts** folder, then double-click **ScheduleItem.js**. |
176 | 176 | 2. Find the following comment: |
177 | | - ```javascript |
| 177 | + ```javascript |
178 | 178 | // TODO: Check if item is starred |
179 | | - ``` |
| 179 | + ``` |
180 | 180 | 3. After this comment, add the following JavaScript code: |
181 | | - ```javascript |
| 181 | + ```javascript |
182 | 182 | if (localStarStorage.isStarred(this.id)) { |
183 | 183 | this.element.classList.add(this.starredClass); |
184 | 184 | } |
185 | | - ``` |
| 185 | + ``` |
186 | 186 | 4. Find the following comment: |
187 | | - ```javascript |
| 187 | + ```javascript |
188 | 188 | // TODO: remove the star from the item |
189 | | - ``` |
190 | | -5. After this the comment, add the following JavaScript code: |
191 | | - ```javascript |
| 189 | + ``` |
| 190 | +5. After this comment, add the following JavaScript code: |
| 191 | + ```javascript |
192 | 192 | this.localStarStorage.removeStar(this.id); |
193 | | - `` |
| 193 | + ``` |
194 | 194 | 6. Find the following comment: |
195 | | - ```javascript |
| 195 | + ```javascript |
196 | 196 | // TODO: add a star to the item |
197 | | - ``` |
| 197 | + ``` |
198 | 198 | 7. After this comment, add the following JavaScript code: |
199 | | - ```javascript |
| 199 | + ```javascript |
200 | 200 | this.localStarStorage.addStar(this.id); |
201 | | - ``` |
| 201 | + ``` |
202 | 202 |
|
203 | | -#### Task 5: Test the application. |
| 203 | +#### Task 5: Test the application |
204 | 204 |
|
205 | | -1. In Solution Explorer, double-click **appcache.manifest**. |
| 205 | +1. In **Solution Explorer**, double-click **appcache.manifest**. |
206 | 206 | 2. Find the following line: |
207 | | - ```javascript |
| 207 | + ```javascript |
208 | 208 | CACHE MANIFEST |
209 | | - ``` |
| 209 | + ``` |
210 | 210 | 3. After the line, insert the following line: |
211 | | - ```javascript |
| 211 | + ```javascript |
212 | 212 | # version 2 |
213 | | - ``` |
214 | | -4. In Solution Explorer, double-click **schedule.htm**. |
| 213 | + ``` |
| 214 | +4. In **Solution Explorer**, double-click **schedule.htm**. |
215 | 215 | 5. On the **Debug** menu, click **Start Without Debugging**. |
216 | | -6. In Microsoft Edge, press F5 to refresh the page. |
217 | | -7. Expand the Windows notification area, right-click **IIS Express**, and then click **Exit**. |
| 216 | +6. In Microsoft Edge, to refresh the page, press F5. |
| 217 | +7. Expand the Windows notification area, right-click **IIS Express**, and then select **Exit**. |
218 | 218 | 8. In the **Confirmation** dialog box, click **Yes**. |
219 | | -9. In Microsoft Edge, click the star icon in the **Registration** box, and verify that the icon is now colored yellow. |
| 219 | +9. In Microsoft Edge, click the star icon in the **Registration** box, and then verify that the icon is now colored yellow. |
220 | 220 | 10. Press F5. |
221 | 221 | 11. Verify that the star icon for **Registration** is still colored yellow. |
222 | 222 | 12. Close Microsoft Edge. |
223 | 223 |
|
224 | | -#### Task 6: Reset Microsoft Edge caching. |
| 224 | +#### Task 6: Reset Microsoft Edge caching |
225 | 225 |
|
226 | | -1. On the Windows taskbar, click **Microsoft Edge**. |
227 | | -2. In the Microsoft Edge, press F10 to display the menu bar. |
| 226 | +1. On the taskbar, click **Microsoft Edge**. |
| 227 | +2. In Microsoft Edge, to display the menu bar, press F10. |
228 | 228 | 3. On the **Tools** menu, click **Internet options**. |
229 | 229 | 4. In the **Internet Options** dialog box, click **Settings**. |
230 | 230 | 5. In the **Website Data Settings** dialog box, click the **Caches and databases** tab. |
231 | 231 | 6. Clear the **Allow website caches and databases** check box, and then click **OK**. |
232 | 232 | 7. In the **Internet Options** dialog box, click **OK**. |
233 | 233 | 8. Close Microsoft Edge. |
234 | 234 |
|
235 | | ->**Results:** After completing this exercise, you will have updated the Schedule page to locally record starred sessions. |
| 235 | +>**Results**: After completing this exercise, you will have updated the **Schedule** page to record starred sessions locally. |
236 | 236 |
|
237 | 237 | ©2018 Microsoft Corporation. All rights reserved. |
238 | 238 |
|
|
0 commit comments