0

I'm a beginner in the middle of trying to make his first website.

Right now, my website uses javascript to get weather information from Yahoo every time a page loads. Is there a way to set things up so it will only try to get information once a day at midnight- even when no one has the website open? Also, I'm hosted by Github pages.

Yifan
  • 326
  • 3
  • 4
  • 18
  • Hint: Store the weather info in a flat file on your server. If, when you go looking for it, the flat file isn't there, or is too old, then go and fetch the information from Yahoo! and store the data in the file - otherwise, just read the info from the flat file. – Adam Jenkins Jun 01 '16 at 18:42

1 Answers1

1

Is there a way to set things up so it will only try to get information once a day at midnight- even when no one has the website open?

Yes you could create a cron task to fetch the information once per night, and then users could get that data from you. This would require the ability to run a task on your server.

Also, I'm hosted by Github pages.

So no, you can't use a cron task. Instead, you could cache the response in the client's cookies or local storage and have it expire in 24 hours. This way each client will check their local cache first, and only fetch if the cache is expired.


last dying breath option:

You could setup a crontask on your development machine to fetch the weather, write it to a file, then push a commit to github, and have it run that task once per night. Then users could fetch the static data from GH Pages.

This may be a bit overkill tho

Mulan
  • 129,518
  • 31
  • 228
  • 259