Skip to content

Set X-Requested-With for startup JS requests

Heinrich Lee Yu requested to merge fix-http-caching-for-startup-js-requests into master

What does this MR do and why?

Set X-Requested-With: XMLHttpRequest for startup JS requests.

This is used by Rails to detect if the request is an AJAX request. We do the same in our axios client: https://gitlab.com/gitlab-org/gitlab/blob/3e370acd81405758016112f6d287009ca0a869e1/app/assets/javascripts/lib/utils/axios_utils.js#L9-10

This impacts HTTP caching because of this code: https://gitlab.com/gitlab-org/gitlab/blob/fd7a09ee1f46e514bdb4237520cf6d9925e6f55f/app/controllers/application_controller.rb#L300-304. We only enable HTTP caching for AJAX requests.

How to set up and validate locally

  1. Open an issue.
  2. Look at the discussions.json request and check the request headers.
  3. Refresh the page. The discussions.json request should return 304 now that it has the correct cache header.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Heinrich Lee Yu

Merge request reports