perf(Navigation): Request nav/footer data only once during BE build
What is changing in this MR?
This implementation requests the navigation/footer data only once and then cache it to be used during the build of the application to avoid hitting the Contentul API many times only to get the same data.
- Update the navigation-hoc and footer-hoc components to receive the data from Nuxt Payload, if for some reason the payload does not exists, it will fetch the data from Contentful
- Create the
getAllLocalesNavData
that fetches all localesby using withAllLocales and create a recursive function that selects the necessary language from the object return from Contentfulby doing one request per language and then grouping the results by locale. - Call the
getAllLocalesNavData
and cache the result using Nuxt Payload to have a single navigation instance for the whole build.
Considerations
- For development builds (aka
yarn dev
) the data will be fetched from Contentful right away, for production builds (akayarn generate
) it will use this approach - Even though this approach works for most pages, pages such as
community
,devsecops
, orpricing
are not using the payload as for some reason it is not detected on these pages, that would be a nice fix for an mvc2 version of this work.
Production | Review app |
---|---|
https://about.gitlab.com/ | https://3626-request-nav-footer-data-only-once-during-be-build.about.gitlab-review.app/ |
The pages below are not using the cached NavigationData for some reason, which means the NavigationData for these pages is being taken by the fallback function.
Build Variables:
-
Use Contentful Preview API
Closes #3626 (closed)
Edited by John Arias Castillo