Performance: Custom response headers
Custom response headers affect the network payload size and can influence browser rendering if headers control caching or content behavior.
response.addHeader("X-Request-ID", requestId);response.addHeader("X-Debug-Info", "Very large debug data string repeated many times...");
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Large custom headers with verbose data | 0 | 0 | Increased due to delayed paint | [X] Bad |
| Minimal essential custom headers | 0 | 0 | Minimal impact on paint timing | [OK] Good |
X-Custom-Header with value 12345 using ResponseEntity in Spring Boot?public ResponseEntity<String> getData() {
return ResponseEntity.ok()
.header("X-Rate-Limit", "1000")
.header("X-Request-ID", "abc123")
.body("Success");
}@GetMapping("/test")
public ResponseEntity<String> test() {
ResponseEntity<String> response = ResponseEntity.ok();
response.header("X-Test", "value");
return response.body("Done");
}X-User-Status with value active only if a user is logged in, otherwise no header. Which is the best way to implement this in a Spring Boot controller method?Pass the test and this pattern moves unknown