Hi @mej,
I totally understand that you are using cookies to store the session ids but the problem is if we try to cache the page at the CDN level, it won’t be possible to do because CDNs will refuse the cache the Page HTML as long as the response header has set-cookie
in it, because it will think that the page content is dynamically dependent on the cookie value.
To mitigate this problem and making sure the pages are long term cache friendly, I would suggest implementing the following approaches:
- Instead of setting the cookies at the PHP level which causes
set-cookie
in the Response Header, please handle it at the JavaScript level.
- You can either take advantage of the browser’s LocalStorage or SessionStorage API to store the data. But for some reason if you must need to use Cookies, then please set the cookies at the JS level as this will not add the
set-cookie
header and the page can be cached. Link: https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie
- You can add an Ajax call to pass the cookie or localstorage data to PHP from your JS script.
If you implement these recommendations, you can still do all the tracking that you are doing but instead of using PHP to setup the cookies, doing that at the JS level so the page HTML can be cached for long term without hampering anything.
Hope this helps. ??