The header of all of my weather Web pages will display any watches, warnings, or advisories issued by the National Weather Service for my local area. They display in a colored box at the top of the page if there are any to be displayed. Otherwise that area of the page is not visible. The problem is that if the status changes and you don’t refresh the page, the box never appears (or else never goes away). Time to add code to automatically refresh that part of the page periodically.
First I created a JSON representation of the data and a way to transfer it to the browser. Next I wrote Ajax code to retrieve the data every 10 minutes. Finally I wrote code to determine what type of notification it is (warning, watch, or advisory), set the color of the box, make the box visible, and display the message. I already had Javascript code to display the warning in a colored box and to make the box visible, but I saw that Knockout could also do this for me. So I adapted my code to provide support functions and let Knockout do the work.
We had a weather advisory today which gave me the opportunity to test the new code and ensure it worked correctly. The advisory appeared at the top of the page while the advisory was in effect, and when it ended the advisory box disappeared from the page. It looks like another successful move to make the page more dynamic and update when conditions change.