1
00:00:02,230 --> 00:00:04,060
I hope you enjoyed the assignment,

2
00:00:04,240 --> 00:00:05,050
in the assignment

3
00:00:05,050 --> 00:00:06,460
we detected something.

4
00:00:06,880 --> 00:00:12,700
If we have a look at a service worker here in our main project again, so make sure to switch back to

5
00:00:12,700 --> 00:00:20,320
that and make sure to clear the storage in your application to use the service worker of the main

6
00:00:20,320 --> 00:00:21,900
project again.

7
00:00:22,030 --> 00:00:23,620
Everything is working here

8
00:00:24,070 --> 00:00:33,150
but one thing we can see here is, that there we also use this regular expression check to see if the request

9
00:00:33,170 --> 00:00:37,410
URL is basically part of our static files.

10
00:00:37,720 --> 00:00:44,430
So here, we actually should face the same issue as we did in our assignment.

11
00:00:44,830 --> 00:00:51,640
So one improvement here could be since we have this generic short slash here which is part of basically

12
00:00:51,730 --> 00:00:52,640
any URL,

13
00:00:52,720 --> 00:00:59,060
if you have a case like this, the better alternative most likely is to create the same helper function

14
00:00:59,060 --> 00:01:04,680
I created in the assignment and you can basically skip and just copy the code if you did the assignment,

15
00:01:04,690 --> 00:01:12,100
if not here's what I did there. I added the isInArray method which takes two inputs, a string and an

16
00:01:12,100 --> 00:01:15,090
array and I want to check if the string as part of the array.

17
00:01:15,220 --> 00:01:21,910
For that, I simply loop through the array with a traditional for loop where I check if i is smaller than

18
00:01:21,910 --> 00:01:31,000
the length and that increment i and in there, I simply check if array[i], so the current

19
00:01:31,000 --> 00:01:33,500
element of the loop is equal to string.

20
00:01:33,820 --> 00:01:35,600
If that's the case, I want to return true,

21
00:01:35,620 --> 00:01:40,530
it means we have a hit and if I finish the loop without a hit, I return false

22
00:01:40,660 --> 00:01:46,970
and now I can use isInArray here, instead of the regular expression and to this array

23
00:01:46,970 --> 00:01:49,710
I pass the request URL as the string

24
00:01:49,720 --> 00:01:53,590
I want to find and the array of course is static files.

25
00:01:53,950 --> 00:02:00,280
So with that, let's save this and go back to the application and there, first of all clear storage to

26
00:02:00,280 --> 00:02:07,120
make sure you have no old data from the assignment lying around, then you can reload twice to install

27
00:02:07,120 --> 00:02:12,000
the service worker and then do all the fetching and it should work fine.

28
00:02:12,040 --> 00:02:15,630
We've fetched the majority from the service worker or from the cache

29
00:02:15,640 --> 00:02:17,100
via the service worker,

30
00:02:17,290 --> 00:02:23,470
we only store or we only fetch the path, the get route dynamically which is exactly what we want to

31
00:02:23,470 --> 00:02:24,220
do.

32
00:02:24,640 --> 00:02:32,320
So this is this improvement, definitely a nice improvement in cases like ours where you do have a generic

33
00:02:32,320 --> 00:02:38,020
string in the array of strings we wanted to check which could be part of unqualifying routes too.
