Cache the CSRF token instead of reading it from the DOM each request
While investigating https://gitlab.com/gitlab-org/gitlab-ce/issues/37767, I found that we're reading the csrf token from the DOM every time we make an AJAX request.
// Up-to-date Cross-Site Request Forgery token
function csrfToken() {
return $('meta[name=csrf-token]').attr('content');
}
That certainly adds up when we make 3-5 requests on page load, but really accumulates when we're polling.
These DOM reads are an unnecessary performance burden. We could easily cache the token somewhere in memory and access it there.
cc: @jschatz1