Caching small videos for Gif replacement

I’d like to request caching for small mp4 and webm files to replace gifs. This was asked before in Are gifs images or videos? but might have been confused by someone who thought the poster wanted to steal GIPHY’s content.

An animated gif produces huge file sizes. Sites like GIPHY will convert their gifs into mp4s/webms to reduce their sizes significantly.

If Cloudflare caches gifs and not small mp4s/webms, it discourages good behavior on the web. I propose it should encourage, or at least support, conversion of gifs by caching the other formats. Maybe Cloudflare could even convert gifs automatically at the edge, though rewriting HTML to load video might be risky (webp will animate too and could be more seamlessly converted).

Perhaps a size limit would allow Cloudflare to know which mp4/webm videos are GIF replacements and which are full streaming videos? < 1MB for example.

Thanks!

I don’t think they should do it, but I anyway am very certain that you are already allowed to use small MP4 videos since I would consider them typical webcontent.

Anyway if you have a GIF dont convert it to MP4 but rather to:

  • aPNG (animated PNG)
  • WebP (yes they support animations)
  • AVIFs (AVIF/AVIS Image Sequence, also supports animation)
  • JXL (JXLa, animated JXL, magic bit set to jxla)

The problem with MP4 is, that it by definition is a container, able to contain anything… Video, Audio, Subtitles, chapters. Thats no typical webcontent!

Instead going with one of the new webformats you would be able to use way smaller files for the losslessly same file, with no concerns for Cloudflare.

Here some examples:

GIF (original):

aPNG:

WebP:

AVIFs:

JXL:

In these example some are losslessly created, some not. It’s just for reference. Please use any of these formats. Thanks!

For JXL you may have to go in chrome to chrome://flags/ and turn on Enable JXL image format
So see which of these formats is doing you best and go for it. This very sure is risk-free, as typical webcontent. WebP I think does atm have a lot of libs/cli tools which you could use to automatically convert to. The others (aPNG) are mostly bigger, or (AFIVs & JXL) do not have so much support, but should at same quality even be smaller then WebP.

Alternatively WebM could be used for this aswell, but again Audio is no typical webcontent in my eyes and WebM is capable of including Audio. Animated pictures are always typical webcontent.

animated AVIF & JXL are not supported on all enddevices, so may just use them with a fallback.

Just my 2cents.

2 Likes

I’m not sure what that has to do with caching small MP4 files, unless you mean that Cloudflare can’t know it is a gif alternative. It would still be worth caching, whatever the content.

Those other formats are great options. Thank you for bringing them up! I didn’t know about JXL.

GIPHY actually uses WebP for the gif thumb and WebM for the larger version of the gif on their website.

I’m in search of the best performance and user experience I can get for the web, and thus I would still like to submit my feature request to cache smaller (a few MB or less) video files. Though MP4 can contain other content, it doesn’t seem to me to be an issue. It is very often used for video, and caching it with something other than video inside would still be benefit the end user and not hurt the web as far as I can tell.

Because the size (in this case) does not matter at all, what matters is ToS 2.8:

2.8 Limitation on Serving Non-HTML Content

The Services are offered primarily as a platform to cache and serve web pages and websites. Unless explicitly included as part of a Paid Service purchased by you, you agree to use the Services solely for the purpose of (i) serving web pages as viewed through a web browser or other functionally equivalent applications, including rendering Hypertext Markup Language (HTML) or other functional equivalents, and (ii) serving web APIs subject to the restrictions set forth in this Section 2.8. Use of the Services for serving video or a disproportionate percentage of pictures, audio files, or other non-HTML content is prohibited, unless purchased separately as part of a Paid Service or expressly allowed under our Supplemental Terms for a specific Service. If we determine you have breached this Section 2.8, we may immediately suspend or restrict your use of the Services, or limit End User access to certain of your resources through the Services.

Read it carefully and you will know that some things are not allowed. So strictly speaking: it’s not meant to serve video. As soon as you put pictures into a videocontainer it is a video. If it’s in a animated picture container it is sanimated picture. Pictures are allowed if not disproportionate percentage of pictures.

If you want to serve videos through Cloudflare please contact the sales department, since otherwise this would be again the ToS.

Can you please elaborate why exactly it is no issue and how you prove that? Since I thb think this is a lose claim. A container which is able to contain nearly everything - even things that do not belong there, could indeed be a problem, also it’s no typical web content.

Sorry but you are totally wrong, it never was made to be a “alternative to GIFs” nor is this it’s primary function. Please have a read here: MPEG-4 Part 14 - Wikipedia
about what MP4 (MPEG-4 Part 14) is. It is a video-containerformat that does not have anything to do with GIF. You can use it as a alternative for it, but it is capable of doing way more, and if you are just about animated pictures with no audio/subtitles/chapters then the above listed formats are for you. No need for Cloudflare to losen it’s ToS or change anything.

They don’t use Cloudflare AFAIK, they pretty sure use a high paid plan at fastly. I can totally understand why Cloudflare don’t want to cache MP4 (video in general) for free and I support it.

If you still like to go for the MP4 format you can do so, just contact sales and get you a special plan that includes MP4 or whatever.

1 Like

The subscription agreement dictates what is not allowed on Cloudflare’s services. That doesn’t necessarily mean they can’t support caching small videos. We formats that could be used against their terms. For example, you can use HTML to “engage in any activities that are illegal,” but that doesn’t mean they should no longer support caching HTML. I only mention this to explain why I don’t think my request is completely crazy. We still must abide by their ToS with whatever they allow to be cached.

While it could be up for debate, I would say animated GIFs are a form of video. A very inefficient form of video. So again, I don’t think my request is out of the question. And since websites like GIPHY use video alternatives to GIF to provide a better user experience, I thought it would be nice to use it on my sites.

I understand Cloudflare may never allow it. I understand that MP4 was not created to be be an alternative to GIFs. I understand MP4s can contain content which would be against their ToS. I wouldn’t want Cloudflare to loosen it’s ToS. I understand they may decide that any video that isn’t one of the image formats shouldn’t be allowed. I just wanted to submit a feature request.

Until, if ever, Cloudflare supports it, I will reach out to sales for a special plan or use the animated image formats as you recommended earlier (webp, aviff, etc). Thank you for your suggestions and explanations, @M4rt1n!

There is also Cloudfront that can be used for this purpose. Software7 That should work.

You are very welcome!

Yes exactly that is what I think makes sense, there are cheaper and better solutions then Amazons S3 storage, but you can go with what service satisfies your needs.

Just outsource the content that may is against Cloudflares ToS to another service and you are good to go. Since these files then are served from another domain, make sure to impelement dns-prefetch or preconnect, to make this having a lesser impact on your sites performance.