Updating Forecast

The revised site has been running for several days now.  Not having as many problems as I expected.  That’s a good thing.  So I decided to add a new feature.  I tend to leave the Web page open for hours at a time and look at the station data periodically, as it updates automatically.  The problem is that the forecast from he NWS is static.  To get ti to update requires clicking on the button to refresh that page.  So I added code to have it update automatically.  My NWS forecast PHP class now can serialize itself to JSON.  I created a new page that returns that JSON data to the browser.  And I added client side Knockout data binding for those fields.  So far so good.

While I was testing the data binding, I learned that I had a bug in my Knockout code.  If I had used proper JavaScript exception handling I would have noticed it earlier.  I was retrieving the data from the server on a schedule, with some data refreshing more frequently than other data.  What I didn’t realize was that Knockout was throwing exceptions when I mapped the data model up until I retrieved all of the fields at least once.  So now I “prime the pump” and retrieve everything once up front.  I had to add that code to all of my Web pages that use Knockout.  Then I added a bit more exception handling code.  I’m not happy with it, but at least I have something there.  I also found a bug in one field that caused it to show as zero most of the time.  So I fixed that one as well.

I also made the mistake of running my pages past a Web page optimization site.  Of course I got called out for having so much JavaScript code.  So I added minify to my Web site.  Minify is PHP code to combine and compress multiple JavaScript files on demand.  That helped my load times out a bit, and the optimizer had one less thing to complain about.  There’s still some more I can do to make the pages load a little bit faster.  So I may still do some more work in that area.