diff --git a/control/Director.php b/control/Director.php index d6ddc97ca..3f62ecc39 100644 --- a/control/Director.php +++ b/control/Director.php @@ -918,6 +918,9 @@ class Director implements TemplateGlobalProvider { * by checking for a custom header set by jQuery or * wether a manually set request-parameter 'ajax' is present. * + * Note that if you plan to use this to alter your HTTP response on a cached page, + * you should add X-Requested-With to the Vary header. + * * @return boolean */ public static function is_ajax() { diff --git a/docs/en/02_Developer_Guides/08_Performance/02_HTTP_Cache_Headers.md b/docs/en/02_Developer_Guides/08_Performance/02_HTTP_Cache_Headers.md index c47c1fcd6..e4df33def 100644 --- a/docs/en/02_Developer_Guides/08_Performance/02_HTTP_Cache_Headers.md +++ b/docs/en/02_Developer_Guides/08_Performance/02_HTTP_Cache_Headers.md @@ -209,7 +209,7 @@ when calculating a cache key, usually in addition to the full URL path. By default, SilverStripe will output a `Vary` header with the following content: ``` -Vary: X-Requested-With, X-Forwarded-Protocol +Vary: X-Forwarded-Protocol ``` To change the value of the `Vary` header, you can change this value by specifying the header in configuration. @@ -218,3 +218,6 @@ To change the value of the `Vary` header, you can change this value by specifyin HTTP: vary: "" ``` + +Note that if you use `Director::is_ajax()` on cached pages then you should add `X-Requested-With` to the vary +header.