Learning Promise, Cache API, and Indexed DB

Second chapter is about Promise. I create one more folder for training. Set the web server to specific folder and visit browser. Page did not changed, still display my previous project.


So browser still remember the cache for this url and display old content. I restart the web server and refresh the browser. No change.

Finally I clear the site data via console log and it works.

One thing I notice the different to picture in Dicoding is sort of the events. While Dicoding picture say Pendaftaran berhasil comes first and mine comes last. Let’s see whether this will be a problem in the future or not. But I think, browser will run sw.js first then display log Pendaftaran berhasil. I think.

Aha! On the second picture, Dicoding also has Pendaftaran berhasil at the last record. Same as mine.

Code at github

News Reader (Cache API)

In News reader section, there is a code that author do not explain which code to modify. Author only mention something related to urlsToCache and else function. I think it is on fetch function in service-worker.js.

Somehow I missed the getArticleByID part.

Code at github

Indexed DB

Dicoding still refer v2.1.3 but currently IDB already has v5.x.x. Perhaps to follow the course, we will use referred version. But on task submission, we better to use latest version. Perhaps.

Beware of brackets! Especially when calling resolve() inside getArticleByID in api.js. Make sure it would be like this one,

Push Notification

This screen is displayed on the tutorial but no longer displayed when registering new Firebase Cloud Messaging. Either using Google Analytics or not. Both don’t display this screen anymore.

I tried to install web push package npm install web-push -g. But I found error looks like this. Dicoding said I have to install NodeJs and NPM to simulate web push notification. Okay.

After installing NodeJS and NPM, it still display the same error. Fine. I search for solution in Stackoverflow and find this working charmly.

sudo chown -R $(whoami) /usr/local/bin /usr/local/lib /usr/local/include /usr/local/share

Aftet this one, I am a bit lost.

I skip the tutorial and fast forward to the submission. (finger crossed)

I post my journey to learn new programming in Medium. I write in amyunus.com too (Bahasa Indonesia), mostly travel and review