Guideline for passing single objects from backend to frontend (current user, current project, ...)
For https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13866 there was a Slack discussion what would be the preferred way to pass single objects (not lists) from backend to frontend. We currently have multiple ways to do this in our code base:
- global (property of
window
) (we want to reduce that: https://gitlab.com/gitlab-org/gitlab-ce/issues/20983) - part of
gon
(we want to reduce that, couldn't find the issue) - as service / singleton + Ajax call (https://gitlab.com/gitlab-org/gitlab-ce/issues/31953)
- via Vuex + Ajax call (https://gitlab.com/gitlab-org/gitlab-ce/issues/33985)
- data attributes
-
<script id="..." type="application/json">
andJSON.parse(document.getElementById('...').innerHTML)
Ajax calls can be cached in localstorage to increase performance.
Edited by Inactive Account