Best practice for relation to global

default discord avatar
oloflarsson
3 months ago
6

What would be the best practice for dealing with global data like a footer that should be on every page on the site and be the same for every page? The obvious answer would be to use a global called Footer i think and fill in the info there, however, would that mean i would need to make an extra request to the rest api along with the rest api request for the page itself?

  • default discord avatar
    yhn5790
    3 months ago

    @oloflarsson



    It's that or you would have do a relation and attach the footer for every doc



    If you are using something like nextJs or astro this could be part of your layout component

  • default discord avatar
    olarssony
    3 months ago

    ah allright, so relation would be what makes most sense then i guess. thank you

  • discord user avatar
    denolfe
    Payload Team
    3 months ago

    Best practice for relation to global

  • discord user avatar
    jacobsfletch
    Payload Team
    3 months ago

    We typically

    do

    make that extra request for global data like header, mega menus, and footer. It’s simpler this way. Alternatively you’d need to open a custom endpoint which aggregates the api request with your globals, and the savings would not worth it imo. You probably wouldn’t want to use an after read hook because it runs far too often.

  • default discord avatar
    oloflarsson
    3 months ago

    But wouldnt it be practically simpler like yhb said to create a relation to the footer collection/global and you wouldnt have to do any extra api calls? or would that have some other drawback im missing?

  • discord user avatar
    jacobsfletch
    Payload Team
    3 months ago

    This would mean adding a relation to every single document, certainly possible but I don’t see a huge benefit in doing this

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.