gifstream
endless gifs, streamed to the browser.
2023-08-28 (1 year ago)streaming gif frames to the browser
this page might not work correctly on mobile or safari
you may have noticed that the clock is a little off, that’s because it’s not actually a clock, it’s a gif that’s updated every second.
you can check it out here if your skeptical.
if you look at the page, it never finishes loading, that’s because the gif frames are being streamed to the browser as they are generated.
i do this using a library i wrote called gifstream.
it’s a simple library for rust that takes a generator function and returns an asynchronous stream of encoded gif frames.
you don’t have to just stream boring gifs though, you can stream anything you want, like a clock, or a counter, or something interactive.
interactive gifs
submit some text and see what happens
^ also a gif by the way.
the gif is being updated every 500ms
, so it’s not exactly interactive, but it’s close enough. i could make it update every 10ms
,
but that would be a waste of bandwidth, and cpu time.
you can also share the gif with your friends, just send them the url, and they’ll see the same thing you do.
these images are being generated using my langauge, quilt
why it works
the gif spec does not specify how many frames are in a gif, so we can send a gif with an infinite number of frames.
when the gif is requested, it the browser first recieves the gif header and the first frame, then it waits for the next frames to be downloaded. since we keep generated frames, it will keep downloading frames and displaying them until the connection is closed.
inspiration
this library and blog post was inspired by https://hookrace.net/blog/time.gif/
source code
gifs on this page: https://github.com/nathanielfernandes/yabba