One of the most useful features to implement on a CDN-powered webpage is to define the "Time To Live" (TTL) for filetypes. This will tell the CDN servers how long to wait before checking for a changed/updated version of the file, and tells a web browser how long it should keep a file locally cached on the computer before requesting the file again.
The EdgeRules feature is available only on Enterprise plans
TTL and browser cache are manipulated with the max-age value for the Cache Control header. In the image below we are setting the TTL (CDN Cache) to 30 days and max-age (Browser Cache) to one day. Both values are defined in seconds (60 seconds * 60 minutes * 24 hours = 86400 seconds in 1 day; 60 seconds * 60 minutes * 24 hours * 30 days = 2592000 seconds in 30 days
Creating the Rule
Verifying the Rule
-
Curl before TTL expires
In this result the browser will cache the image, and will not request it from the CDN again for another 24 hours (unless the user manually clears the browser's cache).
~$ curl -I http://foo.bar.netdna-cdn.com/image.png HTTP/1.1 200 OK Date: Sun, 25 Aug 2013 12:32:21 GMT Content-Type: image/png Content-Length: 12345 Connection: keep-alive Last-Modified: Wed, 31 Jul 2013 20:09:33 GMT Vary: User-Agent Server: NetDNA-cache/2.2 Cache-Control: max-age=86400 X-Cache: HIT Accept-Ranges: bytes
-
Curl after TTL expires
In this result, the Cache-Control: max-age has expired, and so the browser will request the image from the CDN.
~$ curl -I http://foo.bar.netdna-cdn.com/image.png HTTP/1.1 200 OK Date: Sun, 25 Aug 2013 12:32:21 GMT Content-Type: image/png Content-Length: 12345 Connection: keep-alive Last-Modified: Wed, 31 Jul 2013 20:09:33 GMT Vary: User-Agent Server: NetDNA-cache/2.2 Cache-Control: max-age=86400 X-Cache: EXPIRED Accept-Ranges: bytes
-
Resulting Nginx Configuration Block
location ~ \.(ico|pdf|flv|jp?g|png|gif|js|css|webp|swf)(\.gz)?(\?.*)?$ { more_set_headers 'Cache-Control: max-age=86400'; ... proxy_cache_valid 200 2592000; ... }
We hope this article was helpful and as always, If there are any questions or concerns about any of the topics mentioned in this article, please feel free to reach out to support - we are available 24/7 by chat or email!