Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Payload Image Url not cached? NeXT js, vercel

default discord avatar
waterman_last year
10

Hey, i have a production issue where a 3kb logo takes some time to load even and after vercel has cached it. About 0.5 sec flickering effect on load, but also the image has to cache again after 60 sec it seems like.



I use the image component , I use a s3 bucket(supabase). At first i also thought there was an issue with the data i get from payload, if it is revalidating or returning another url, but i have tried to hardcode the direct url to the supabase media file Which works perfectly fine, but if i hardcode the url from my payload media image it doesnt work like i want. It just flickering on load and some cache seems to be cleared every 60 sec Which makes it take 5sec + to load…



I can share code or explain more detailed if you need to know anything more. I appreciate all the help



To see the problem yourself you can visit

https://www.ondev.se

, i Will attatch two images showing the cache headers to an image from payload and the direct url to an image to my s3 bucket



My question wasnt so clear, but i ended up solving the issue by disablePayloadAccess in the s3 media configuriation in the payload config file.


I also changed from supabase to aws s3 since when disabling payloadaccess gives the direct url to the files and i didnt get it to work when the files where gonna be displayed by anyone…

  • default discord avatar
    panic07last year

    Where did you add this? I tried it here but getting errors:


    plugins: [ s3Storage({ collections: { media: true, }, bucket: process.env.S3_BUCKET!, config: { credentials: { accessKeyId: process.env.S3_ACCESS_KEY_ID!, secretAccessKey: process.env.S3_SECRET_ACCESS_KEY!, }, region: process.env.S3_REGION, }, disablePayloadAccessControl: true, }), ],
  • default discord avatar
    zephury.last year

    I do not allow public read for my images. I use s3/minio buckets, leaving payload access control in place. I do not modify the media file's path to include my bucket's url or anything like that. Payload fetches it, provides it to

    next/image

    , then it is cached however it is configured within nextjs.


    60 seconds is the default cache time

    https://nextjs.org/docs/app/api-reference/components/image#caching-behavior
  • default discord avatar
    panic07last year

    yes but on a large scale site with lots of traffic using next/image is costly and also with payload cms using api routes to fetch images which is a serverless function invocation every image every page request, cost is gotta be high.

  • default discord avatar
    zephury.last year

    then a custom loader would be more ideal, with an integration with something that transforms image sizes on request, would it not?


    To my knowledge, you cannot get the images formatted by next/image saved on your remote image storage. I believe Payload is working on their own image loader api, so that you can store on s3 and persist those image sizes.

  • default discord avatar
    panic07last year

    I jsut wanna server the site with the S3 bucket URL and not

    /api/media
  • default discord avatar
    zephury.last year

    I could be wrong, because I haven't spent

    that

    much time on this topic, so take it with a grain of salt, but;



    It doesn't matter what url you give next/image. its going to query the url, then generate the optimized (resized) version the same way. only with a

    loader

    can you change the behavior, so that it doesnt resize the images and store them on disk itself.



    a custom loader can skip the sharp image processing part and all of the vercel costs you're talking about. not a different url

  • default discord avatar
    panic07last year

    im passing unoptimized cause we optimize them before uploading.

  • default discord avatar
    zephury.last year

    you could just use a regular image tag with your own srcset and map the urls to a cdn infront of your bucket then; what would the reason for using next/image be? hope you don't think I'm being confrontational or something, I try to help as many people as I can, but sometimes it can be a learning experience as well

  • default discord avatar
    panic07last year

    this hasnt been about next/image, its been about getting payload to return my bucket URL for the image and not using api/media

  • default discord avatar
    zephury.last year
    https://payloadcms.com/docs/upload/storage-adapters#collection-specific-options

    original post was about next/image, so i assumed this was the topic



    generateFileURL

    is what you're looking for

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.