While not a direct solution for your server-side approach, you could consider using a browser extension WebLabeler: Environment Marker & Indicator) to visually indicate the environment (e.g., "TEST" or "PROD"). This adds a persistent label at the top or bottom of the page, unaffected by AJAX or server-side changes.