Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mattbridges's avatar

Session cookies and Cloudfront

I have a very specific use case. Redeveloping a site that will be behind cloudfront. I'd like to aggressively cache the public (non logged in) parts of the site. When a user is logged in the non logged parts of the site are personalised - nav bar, etc etc.

Cloudfront will let us direct traffic to our origin server based on cookies. Which is great Ie: if you have cookie x then by-pass the cdn and fetch from the origin servers.

I would use the session cookie that laravel creates out of the box for this but the problem is the that session cookie exists all the time as it's got the csrf token and other gubbins in it.

Can anyone suggest an elegant way to deal with this?

(As I mentioned above we're not using s3 buckets for the CDN we're using origin servers)

0 likes
0 replies

Please or to participate in this conversation.