Rohil
Rohil
Explore posts from servers
CDCloudflare Developers
Created by Rohil on 1/9/2025 in #workers-help
environment variables return undefined when i deploy
No description
3 replies
CDCloudflare Developers
Created by Rohil on 1/9/2025 in #workers-help
ENOSPC: no space left on device - in cloudflare workers when i try to deploy my next.js app
No description
52 replies
CDCloudflare Developers
Created by Rohil on 1/8/2025 in #workers-help
How to optimize images that are external?
Hi. I'm using this code
const normalizeSrc = (src: string) => {
return src.startsWith("/") ? src.slice(1) : src;
};

export default function cloudflareLoader({
src,
width,
quality,
}: { src: string; width: number; quality?: number }) {
if (process.env.NODE_ENV === "development") {
return src;
}
const params = [`width=${width}`];
if (quality) {
params.push(`quality=${quality}`);
}
const paramsString = params.join(",");

return `/cgi/image/${paramsString}/${normalizeSrc(src)}
}
const normalizeSrc = (src: string) => {
return src.startsWith("/") ? src.slice(1) : src;
};

export default function cloudflareLoader({
src,
width,
quality,
}: { src: string; width: number; quality?: number }) {
if (process.env.NODE_ENV === "development") {
return src;
}
const params = [`width=${width}`];
if (quality) {
params.push(`quality=${quality}`);
}
const paramsString = params.join(",");

return `/cgi/image/${paramsString}/${normalizeSrc(src)}
}
besides my local images from the public directory in next.js, i have a dynamic page where the images are coming from a different source https://data.companyname.com/ppic/test.jpeg how can i use this in image in the custom loader and optimize it? at the moment they are not loading at all thanks
5 replies