-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need help: compressing images #804
Comments
This is not a code solution, which will probably also generate multiple sizes for multiple devices, but meanwhile consider ImgBot? It should do an average of 10-15%-ish for all images based on some XP with it. It runs as in installable github action so its also close to 0 effort |
How do I enable it? I think I installed the “app” but not sure what the next step is |
Most bandwidth gets eaten by GIFs, so image optimizations alone would be insignificant. This GIF alone is 2.5 MB (after lossy compression, the original is 4 MB - almost the size of all png and jpg pictures combined). And it's from A Complete Guide to useEffect, which I assume is one of the more popular articles. I fixed similar bandwidth issues on Vercel by converting GIFs to MP4 (2.5MB ≈ 300-400kb). A quick fix alternative to that is to find smaller GIFs or substitute GIFs with still pictures. |
i would suggest to serve images and gifs with |
Another option you can consider is moving GIFs/MP4s into Blob storage. Haven't tested this but something like: import { head } from '@vercel/blob';
import Image from 'next/image';
export async function Video({ alt, src }) {
let { url, contentType } = await head(src);
if (contentType.startsWith('video/')) {
return <video src={url} controls />;
}
return <Image alt={alt} src={url} unoptimized />;
} |
Would you be open to replacing the .gif files with .webm? Why use mp4 when webm offers even smaller filesizes? @gaearon |
Sure webm sounds good. Re: blob, don't want to depend on third party services ideally. |
Done, PR Open EDIT: My bad, webm's are a bit broken. Fixing |
@gaearon I've been stuck on this and I can't sleep. I've learnt a lot about mdx and SSR in the process, and I'm enjoying it. I've watched your remix conf talk about react from another dimension, and am eating away at the blog posts trying to decipher how to make it work. It's being a pleasant experience so far |
I've rewritten parts of the functionality of your blog with a new create-next-app to try and replicate it and I do not get this issue |
It seems to be an issue with the way clientside navigation is handled by next js. Here are the request headers: Here is a failed request header for the web before reload when navigating to the page from home: GET /interval-wrong.webm HTTP/1.1 Here is a request header for the webm after page refresh: GET /a-complete-guide-to-useeffect/interval-wrong.webm HTTP/1.1 here is succesful response header for the same webm: Any suggestions? I have tried with relative and absolute paths and something in between. |
It works on the preview on Desktop: https://overreactedio-git-fork-quantgeekdev-feature-medi-71702e-gaearon.vercel.app/a-complete-guide-to-useeffect/ But it breaks on Safari. Even thought webms are supported on Safari as of 2022. I will get back to this again in the morning - does anyone have any suggestions? |
I'm still trying to figure this out. Any input is greatly appreciated |
I only just realized that production "overreacted.io" doesn't work on Safari or Chrome on iOS either 😭😭😭 I didn't actually introduce a bug, I just happened to discover it... Let's see if I have what it takes to fix it EDIT: By "doesn't work" I mean that when you navigate to a page with gifs, such as the guide on useEffect, it won't load the gifs on the first load and will only load them on re-loading the page |
@gaearon Submitted a new pull request with a cleaner commit history. Hope you find it useful |
I'm gonna run out of bandwidth with these unoptimized images. They used to be optimized when the website was using Gatsby but I lost it during migration. I'd appreciate if someone could run some script to get them all optimized once.
No real need to make them optimized at build time. Just let's do this once for existing images.
The text was updated successfully, but these errors were encountered: