Use CDN with Cookie-set sent from origin
Important note
This tutorial assumes you have already created a pull zone.Scenarios vary from case to to case when/where cookies can be used on your website and the essential product is cookie-set on origin files used for either authentication, session id, etc. Cookies are, by nature, un-cacheable and therefore files containing these portions of codes are also un-cacheable which adds bad performance experience when loading CDN assets containing cookie-set.
As all other un-cacheable files, CDN will only work as a simple proxy when end user requests cookie-file from CDN – each time CDN will proxy this request to origin and deliver file via reverse path:
Browser (end user) —> CDN —> Origin —> CDN —> Browser (end user). This scenario will pile up the load time which is not performance experience you want. Http header containing cookie-set:|
1 2 3 4 |
HTTP/1.1 200 OK Content-type: text/html Set-Cookie: name=value Set-Cookie: name2=value2; Expires=Fri, 05-Apr-2013 10:11:12 GMT |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
curl -I http://foo.bar.netdna-cdn.com/file.ext HTTP/1.1 200 OK Date: Fri, 05 Apr 2013 14:12:20 GMT Content-Type: text/css Connection: keep-alive Cache-Control: max-age=999999, public Expires: Thu, 21 May 2014 20:00:00 GMT Vary: Accept-Encoding Last-Modified: Thu, 24 Jan 2013 20:00:00 GMT Set-Cookie: Name=xxxxxxxxxxxxxxxxxxxxxxxxxx; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.domain.com Server: NetDNA-cache/2.2 X-Cache: MISS <---------------- FILE NOT CACHED |
Solution for this gap would be to simply ignore cookies in requests and force CDN to cache that file(s). We have implemented useful option you can reach through the control panel and thick the box next to it — Strip All Cookies — :
Re-run previous command and you should be able to verify that file is now successfully cached (X-Cache: HIT):|
1 2 3 4 5 6 7 8 9 10 11 12 |
curl -I http://foo.bar.netdna-cdn.com/file.ext HTTP/1.1 200 OK Date: Fri, 05 Apr 2013 14:12:20 GMT Content-Type: text/css Connection: keep-alive Cache-Control: max-age=999999, public Expires: Thu, 21 May 2014 20:00:00 GMT Vary: Accept-Encoding Last-Modified: Thu, 24 Jan 2013 20:00:00 GMT Set-Cookie: Name=xxxxxxxxxxxxxxxxxxxxxxxxxx; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.domain.com Server: NetDNA-cache/2.2 X-Cache: HIT <---------------- FILE CACHED |
Support
