Want to create a GIf that performs an HTTP request

Is it possible to embed js code (or any other code) in a GIF or any other type of image? For example I want to:

  1. create an animated image that moves (for example a GIF).
  2. every 5 minutes perform an http request
  3. if the results of the http request is true then change the GIF

for example a gif that changes from the sun to the moon depending on the time of day?

I am open to any technology or image type or tools. your help is appreciated

thanks