I hope you enjoyed the assignment,
in the assignment
we detected something.
If we have a look at a service worker here in our main project again, so make sure to switch back to
that and make sure to clear the storage in your application to use the service worker of the main
project again.
Everything is working here
but one thing we can see here is, that there we also use this regular expression check to see if the request
URL is basically part of our static files.
So here, we actually should face the same issue as we did in our assignment.
So one improvement here could be since we have this generic short slash here which is part of basically
any URL,
if you have a case like this, the better alternative most likely is to create the same helper function
I created in the assignment and you can basically skip and just copy the code if you did the assignment,
if not here's what I did there. I added the isInArray method which takes two inputs, a string and an
array and I want to check if the string as part of the array.
For that, I simply loop through the array with a traditional for loop where I check if i is smaller than
the length and that increment i and in there, I simply check if array[i], so the current
element of the loop is equal to string.
If that's the case, I want to return true,
it means we have a hit and if I finish the loop without a hit, I return false
and now I can use isInArray here, instead of the regular expression and to this array
I pass the request URL as the string
I want to find and the array of course is static files.
So with that, let's save this and go back to the application and there, first of all clear storage to
make sure you have no old data from the assignment lying around, then you can reload twice to install
the service worker and then do all the fetching and it should work fine.
We've fetched the majority from the service worker or from the cache
via the service worker,
we only store or we only fetch the path, the get route dynamically which is exactly what we want to
do.
So this is this improvement, definitely a nice improvement in cases like ours where you do have a generic
string in the array of strings we wanted to check which could be part of unqualifying routes too.