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.

Best practice for relation to global

default discord avatar
oloflarsson2 years 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
    yhn57902 years ago
    @277817202613420042

    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
    olarssony2 years ago

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

  • discord user avatar
    denolfe
    2 years ago

    Best practice for relation to global

  • discord user avatar
    jacobsfletch
    2 years 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
    oloflarsson2 years 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
    2 years ago

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

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.